2

我正在使用弹簧。我有这堂课:

@Service
public class FooService {

    @Value("${xml.file.path}")
    String xmlFilePath;

    @Autowired
    ResourceLoader ctx;
}

我真的很讨厌接线属性,并且更喜欢使用构造函数,但是我想出的任何事情都得到一个奇怪的“类 FooService 中的构造函数 FooService 不能应用于给定类型”。在这种情况下可以使用建筑布线吗?

4

1 回答 1

1

这应该有效:

@Service
public class FooService {
    private String xmlFilePath;
    private ResourceLoader ctx;

    @Autowired
    public FooService(@Value("${xml.file.path}") String xmlFilePath, ResourceLoader ctx) {
        super();
        this.xmlFilePath = xmlFilePath;
        this.ctx = ctx;
    }
}
于 2015-09-11T13:02:42.783 回答