Automatic component detection using spring annotations

I was able to set up spring to automatically detect my components using @Autowire annotations. However, the problem is that not all components are automatically connected.
In particular, my DAOs are bound, but my service objects are not. 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?

+1


source to share


1 answer


If spring is not complaining about anything, but it is not connected yet, there are several possible reasons, from most to least likely:



  • There is no corresponding annotation in the service implementation; ie @Component, @Controller, @Service or one of the other annotations.
  • If the implementation is not annotated, it should be exposed as an xml bean definition.
  • The class scan you have set in the xml file does not hit the service.
  • Your services jar is packaged without a directory structure.
+3


source







All Articles