Spring IOC 笔记

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}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值