Spring学习笔记之通过注解配置Bean(1)
来源:互联网 发布:线切割控制编程系统 编辑:程序博客网 时间:2024/06/05 07:41
1、配置形式
①、基于XML文件的方式;
②、基于注解配置Bean
2、Bean的配置方式
①通过全类名(反射)
②通过工厂方法(静态方法&实例工厂方法)
③FactoryBean
3、特定组件
@Component:基本注解,标识了一个受Spring管理的组件
@Repository:标识持久层组件
@Service:标识服务层(业务层组件)
@Controller:标识表现层组件
当在组件类上使用了特定的注解之后,还需要再Spring的配置文件中声明 context:component-scan
-base-package属性指定一个需要扫描的基类包,Spring容器将会扫描这个基类包里及其所有子包中的所有类,
-当扫描多个包时,可以使用逗号分隔
-如果仅希望扫描特定的类而非所有类,可使用resource-pattern属性过滤特定的类
context:include-filter子节点表示要包含的目标类
context:exclude-fileter子节点表示要排除在外的目标类
context:component-scan下可以拥有若干个context:include-filter和context:exclude-fileter子节点
<!-- 指定Spring IOC 容器扫描的包 --><!-- 可以通过resource-pattern扫描指定的资源 --><!-- <context:component-scan base-package="com.jhh.spring.beans.annotation" resource-pattern="repository/*.class"></context:component-scan> --><!-- use-default-filters true 扫描默认的注解 --> <context:component-scan base-package="com.jhh.spring.beans.annotation" use-default-filters="false"><!-- 排除哪些指定表达式的组件 annotation 通过注解去指定包含哪些注解排除哪些注解 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/> assignable 通过具体的类去指定包含哪些 排除哪些 <context:exclude-filter type="assignable" expression="com.jhh.spring.beans.annotation.repository.UserRepositoryImpl"/>--><!-- <context:include-filter type="annotation" expression="org.springframework.stereotype.Repository"/>--> <context:include-filter type="assignable" expression="com.jhh.spring.beans.annotation.repository.UserRepositoryImpl"/> </context:component-scan>
阅读全文
1 0
- Spring学习笔记之通过注解配置Bean(1)
- spring学习笔记----通过注解配置Bean(1)
- Spring学习笔记之通过注解配置Bean
- Spring学习笔记之通过注解配置Bean(2)
- spring学习笔记----通过注解配置Bean(2)
- Spring 通过注解配置 Bean(1)
- Spring学习笔记三: 通过注解配置Bean
- JavaEE Spring框架学习笔记(理论学习之通过@Bean注解)
- Spring IoC学习笔记(1):注解配置Bean
- spring学习十一 通过注解配置bean
- 13.Spring学习笔记_通过注解配置Bean(by尚硅谷_佟刚)
- Spring4学习笔记-通过注解配置bean
- Spring学习笔记----注解方式配置bean
- Spring 通过注解配置 Bean(2)
- Spring学习笔记之通过FactoryBean配置Bean
- Spring中通过注解配置bean(1)
- spring通过注解配置Bean
- Spring通过注解配置bean
- MSP430单片机USART串口发送字符和字符串
- elasticsearch 配置外网访问
- Vulkan规范:第四章 4.1
- 单链表-头插法、尾插法和基本运算
- okhttp学习
- Spring学习笔记之通过注解配置Bean(1)
- 文章标题
- 函数的调用过程(栈帧)
- Error:(17, 24) 警告: Application namespace for attribute app:url will be ignored.
- Vulkan规范:第四章 4.2
- Java设计模式--享元模式
- Java SE 7 Archive Downloads
- 深入C/C++之基于CheckStackVars的安全检查(VS2008)
- python: bin函数