@ComponentScan, @EntityScan or @SpringBootApplication

@ComponentScan:扫描组件

@SpringBootApplication=(默认属性)@Configuration+@EnableAutoConfiguration+@ComponentScan


一、SpringBootApplication详解

点击打开链接

二、

@Configuration的注解类标识这个类可以使用SpringIoC容器作为bean定义的来源。@Bean注解告诉Spring,一

个带有@Bean的注解方法将返回一个对象,该对象应该被注册为在Spring应用程序上下文中的bean

2@EnableAutoConfiguration:能够自动配置spring的上下文,试图猜测和配置你想要的bean类,通常会自动根据你的类路径和你的bean定义自动配置。

3@ComponentScan:会自动扫描指定包下的全部标有@Component的类,并注册成bean,当然包括@Component下的子注解@Service,@Repository,@Controller



猜你喜欢

转载自blog.csdn.net/shero1604/article/details/79414578