Spring IOC 笔记
2018-03-08 11:18
302 查看
1.导包
2.使用java config配置Spring
@Configuration//定义以java config来配置spring
@ComponentScan//扫描本路径下所有包
@ComponentScan(“包名”)//指定要扫描的包
@ComponentScan(“basePackage={“”,”“,…}”)//指定多个要扫描的包
3.@Component默认以类名首字母小写为ID名,可以使用@Component(”*“)重新命名
4.不同类实现同一接口在自动装配的使用需要用@Qualifier(“类名ID”)来装备对应类
5.@Bean实现显示注解
6.@profile(“**”)设置profile
7.@ActiveProfiles(”**”)选择profile
8.@Primary标识首选Bean
9.@Scope(”“)//限定作用域
10.使用@PropertySource注解和Environment注入外部的值
11.使用#{}和SpEL表达式注入,使用”?.”判断值是否为空
12.#{2 * T(java.lang.Math).PI * circle.radius}
<!-- 配置spring版本 --> <properties> <org.springframework.version>4.2.1.RELEASE</org.springframework.version> </properties> <dependencies> <!-- Spring基础jar包 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${org.springframework.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${org.springframework.version}</version> </dependency> <!-- 测试包 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version> ${org.springframework.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.9</version> <scope>test</scope> </dependency> </dependencies>
2.使用java config配置Spring
@Configuration//定义以java config来配置spring
@ComponentScan//扫描本路径下所有包
@ComponentScan(“包名”)//指定要扫描的包
@ComponentScan(“basePackage={“”,”“,…}”)//指定多个要扫描的包
3.@Component默认以类名首字母小写为ID名,可以使用@Component(”*“)重新命名
4.不同类实现同一接口在自动装配的使用需要用@Qualifier(“类名ID”)来装备对应类
5.@Bean实现显示注解
6.@profile(“**”)设置profile
7.@ActiveProfiles(”**”)选择profile
8.@Primary标识首选Bean
9.@Scope(”“)//限定作用域
10.使用@PropertySource注解和Environment注入外部的值
11.使用#{}和SpEL表达式注入,使用”?.”判断值是否为空
12.#{2 * T(java.lang.Math).PI * circle.radius}
相关文章推荐
- Spring IOC 学习笔记(一) IoC和DI概述
- Spring的IoC学习笔记之BeanFactoryPostProcessor
- Spring IOC容器学习笔记
- Spring3学习笔记之(spring core之IoC容器基本原理)
- 懒得笔记2 spring DI IOC 的一个例子
- Spring笔记之三:Spring Ioc实例演示(完整代码)
- [spring入门学习笔记][spring的IoC原理]
- 【学习笔记】Spring——IOC创建的三种方式
- Spring之IOC(学习笔记)
- Spring IOC 学习笔记(一) IoC和DI概述
- Spring学习笔记——IOC的一些注解
- spring学习笔记(2)——IOC的理解
- Spring学习笔记:第三章 IoC中的国际化
- Spring学习笔记(二) IoC容器与Bean
- Spring学习笔记之基础、IOC、DI(1)
- Spring IOC笔记
- Rhyme/Spring5.0.2.RELEASE官方英文文档学习笔记(1) Introduction to the Spring IoC container and beans
- Spring 4 学习笔记2:控制反转(IoC)和依赖注入(DI)
- [Spring学习笔记 1 ] Spring 简介,初步知识--Ioc容器详解 基本原理。
- Spring学习笔记之The IoC container