@Configuration+@Bean=@SpringBootApplication+@Bean 川长思鸟来 2022-10-06 04:55 160阅读 0赞 ## 一、@Configuration+@Bean ## @Configuration public class BeanConfig { @Bean public TestBean jAnnotation(){ return new TestBean(); } } ## 二、@SpringBootApplication+@Bean ## @SpringBootApplication public class SApplication { public static void main(String[] args) { SpringApplication.run(Application.class, args); } @Bean public TestBean jAnnotation(){ return new TestBean(); } } ## 三、总结 ## 上述两种实现方式的效果其实是一致的,这是因为@SpringBootApplication包含了@Configuration。 1. **SpringBootConfiguration** ...... @SpringBootConfiguration ...... public @interface SpringBootApplication { ...... } 1. **SpringBootConfiguration** ...... @Configuration ...... public @interface SpringBootConfiguration { ...... }
还没有评论,来说两句吧...