我遇到了 Spring 3 提供的两个注释(@Component 和 @Configuration)
我对这些有点困惑。
这是我读到的关于 @Component
Put this “context:component” in the bean configuration file, it means, enable the auto-scanning feature in Spring. The base-package is indicate where are your components stored, Spring will scan this folder and find out the bean (annotated with @Component) and register it in Spring container.
所以我想知道 @Configuration
有什么用,那么如果 @Controller
将注册我的 bean 而无需在 spring 配置 XML 文件中声明它们。
最佳答案
来自 Book Pro Spring 集成
@Configuration
类和普通的 @Components
类一样,只是使用 @Bean
注释的方法用于工厂 bean。请注意,带有 @Bean
注释方法的 @Component
以相同的方式工作,只是不尊重范围并且重新使用 @Bean
方法调用(没有缓存),所以 @Configuration
是首选,即使它需要 CGLIB
关于java - Spring 3中@Component和@Configuration的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11903053/