特定注解包括:
@Component: 基本注解,标识了一个受 Spring管理的组件
@Respository: 标识持久层组件
@Service: 标识服务层(业务层)组件
@Controller: 标识表现层组件(控制层)
@Autowired:自动装配,根据类型
@Resource:自动装配,根据类型或名字
1.导入jar包
(1)基本jar包
(2)导入aop的jar包
2 创建类,创建方法
3 创建spring配置文件,引入约束
(1)第一天做ioc基本功能,引入约束beans
(2)做spring的ioc注解开发,引入新的约束
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd"
>
4 开启注解扫描
<!--开启注解扫描-->
<!--在包里面扫描类,方法,属性上面所有注解-->
<context:component-scan base-package="cn.et.lesson02"></context:component-scan>
<!--扫描属性上面的注解-->
<context:annotation-config></context:annotation-config>
自定义注解
自定义注解类
public @interface TTT {
}
配置
<context:component-scan base-package="cn.et.lesson02.mvc">
<context:include-filter type="annotation" expression="cn.et.lesson02.TTT"/>
</context:component-scan>