2

I'm using Spring. I have this class:

@Service
public class FooService {

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

    @Autowired
    ResourceLoader ctx;
}

I really hate wiring properties and would prefer to use a constructor but anything I come up is getting a weird "constructor FooService in class FooService cannot be applied to given types". Is it possible to use construction wiring in this case?

luboskrnac
  • 23,973
  • 10
  • 81
  • 92
gaijinco
  • 2,146
  • 4
  • 17
  • 16

1 Answers1

1

This should work:

@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;
    }
}
luboskrnac
  • 23,973
  • 10
  • 81
  • 92
  • So dumb from my part, now I realize that the problem was a test was broken because it was using the default constructor. Weird that message was misleading! – gaijinco Sep 11 '15 at 13:07