1.导包
<!-- 配置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}