@ComponentScan 和 @Configuration
来源:互联网 发布:巨潮资讯 数据库接口 编辑:程序博客网 时间:2024/05/23 01:20
@ComponentScan 如果不设置basePackage的话 默认会扫描包的所有类,所以最好还是写上basePackage ,减少加载时间。默认扫描**/*.class
路径 比如这个注解在com.wuhulala 下面 ,那么会扫描这个包下的所有类还有子包的所有类,比如com.wuhulala.service包的应用
@Configuration 表示这个类中定义了Bean,会把这个类中bean加载到spring容器中
@EnableAutoConfiguration springboot的注解 会在你开启某些功能的时候自动配置
,这个注解告诉Spring Boot根据添加的jar依赖猜测你想如何配置Spring。由于spring-boot-starter-web添加了Tomcat和Spring MVC,所以auto-configuration将假定你正在开发一个web应用,并对Spring进行相应地设置。
我们通常建议您在其他类的根包中找到主应用程序类。@EnableAutoConfiguration 注解通常会放在 main class上, 这为特定的东西隐式的定义了一个基础的“search package”. 比如, 如果你在写一个 JPA application, 有使用了@EnableAutoConfiguration 注解的class的包 回去查找 @Entity 的items.
We generally recommend that you locate your main application class in a root package above other classes. The @EnableAutoConfiguration annotation is often placed on your main class, and it implicitly defines a base “search package” for certain items. For example, if you are writing a JPA application, the package of the @EnableAutoConfiguration annotated class will be used to search for @Entity items.
@SpringBootApplication 相当于 @Configuration、@EnableAutoConfiguration 、 @ComponentScan 三个的作用
@ComponentScan@Configurationpublic class AppConfig { @Bean public Foo foo() { return new Foo(bar()); } @Bean public Bar bar() { return new Bar(); }}
- @ComponentScan 和 @Configuration
- 装配Bean:JavaConfig@Component@ComponentScan@Configuration
- SpringBootApplication等价于 @Configuration @EnableAutoConfiguration @ComponentScan
- @ComponentScan
- @SpringBootApplication 相当于 @Configuration、@EnableAutoConfiguration 、 @ComponentScan 三个的作用
- spring系列之@Configuration注解、@Bean注解以及自动扫描注解@componentScan
- Spring Java Configuration之@Configuration和@Bean
- SpringBoot @ComponentScan 作用
- 理解@ComponentScan注解
- 理解@ComponentScan注解
- @Configuration 和 @Bean
- spring @Configuration 和 @Bean
- @Configuration 和 @Bean
- 怎样去理解@ComponentScan注解
- hibernate的Configuration和配置文件
- Spring @Configuration 和 @Component 区别
- Spring Boot @Configuration 和 @Component
- hibernate的Configuration和配置文件
- First Blog
- Spring AOP(动态代理\动态字节码)精华一页纸
- 10391
- 自适应布局-float
- 开通博客的第一天。
- @ComponentScan 和 @Configuration
- php生成的验证码图片不显示问题
- 题目1060:完数VS盈数
- Frence Repair POJ3253 POJ2431 堆排序
- awk 学习记录1
- Android作为服务器通过USB使用Socket协议向PC客户端发送文件
- 最小编辑距离-poj3356
- hdu 1284 钱币兑换问题 (多重背包)
- 深度学习的目标检测