views:

408

answers:

2

I've managed to configure to spring to auto-detect my components using the @Autowire annotation. However the problem is that not all the components are being Auto wired.
Specifically My DAO's are being bound but my service objects aren't. I have to explicitly create a bean for my service object in the spring xml config file.

Any clue as to why this is happening?

+3  A: 

If spring is not complaining about anything but it's still not being wired, there are a few probable causes, from most to least likely:

  • The service implementation is missing the proper annotation; i.e @Component, @Controller, @Service or one of the other annotations.
  • If the implementation is not annotated it has to be present as an xml bean definition.
  • The classpath-scan you have set up in the xml file does not hit the service.
  • Your jar file with services is packed without directory structure.
krosenvold
A: 

I have a similar situation today where a bean containing the @Resource annotation for a service is not populating a subclass unless I explicitly include the @Component annotation in the subclass. Is there a way to request a subclass to be "wired" with the parent @Resource without requiring annotations in each child class? The way I discovered this was by creating a subclass and failing to include the @Component annotation. I was quickly faced with the dreaded NPE.

Peace, Scott

stanlick