0

I was following this tutorial http://java-diaries.blogspot.com/2011/03/get-started-with-spring-jms-using.html and I do not understand why for an @Service and an @Autowired annotation you need to explicitly create beans in the app-context.xml but for the @Component, it creates one for you. Can someone explain this? Also, is there a way to add the destination and connectionFactory beans using annotations? Or do i need a solution along the lines of Add Bean Programmatically to Spring Web App Context

Community
  • 1
  • 1
jon
  • 253
  • 4
  • 8
  • 16

1 Answers1

1

If you're using the context:component-scan tag, classes annotated with both @Component and @Service will be detected and don't need to be declared in your application context.

@Autowired is different. When you declare a field @Autowired, it means that the bean that's in the app context -- whether declared explicitly or picked up by the component scan -- is injected.

rongenre
  • 1,334
  • 11
  • 21