我正在关注本教程 http://java-diaries.blogspot.com/2011/03/get-started-with-spring-jms-using.html我不明白为什么对于 @Service 和 @Autowired 注释,您需要在 app-context.xml 中显式创建 bean,但对于 @Component,它会为您创建一个。有人可以解释一下吗?另外,有没有办法使用注释添加目标和connectionFactory bean?或者我是否需要类似 Add Bean Programmatically to Spring Web App Context 的解决方案
最佳答案
如果您使用 context:component-scan
标记,则将检测到同时使用 @Component 和 @Service 注解的类,并且不需要在您的应用程序上下文中声明。
@Autowired 是不同的。当您声明一个字段 @Autowired 时,这意味着应用程序上下文中的 bean(无论是显式声明还是由组件扫描拾取)都会被注入(inject)。
关于java - 如何以编程方式将Java中的bean添加到Spring中的app-context.xml中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15903432/