0%

SPRING10–基于注解的配置

1.在jar加入sring-aop.jar加入进来,

2.在xml配置

1
2
3
4
5
6
7
xmlns:aop=”http://www.springframework.org/schema/aop”; 
xmlns:context=”http://www.springframework.org/schema/context”;
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd

3.建立一个model层,如下图,其中testService4是测试类。

4.student类说明

1
2
3
4
5
6
7
8
9
10
@Component
public class student {
private int id;
@Value(“张三”)
private String name;
@Autowired // byType注入,根据is-a的关系
//@Qualifier
//byName注入需要@Autowired和@Qualifier一起配合使用
private School school;
}

5.在xml配置

1
<context:component-scan base-package=“com.bean.service4”/>