注解:
- 代码里特殊的标记,使用注解可以完成功能
- 注解的写法@注解名称(属性名=值)
- 注解可以用在类,方法和属性上面
1、导入jar包
红色框为新添加jar包
2、创建类、创建方法
3、创建spring配置文件,引入约束
(1)引入bean约束
(2)做springioc注解开发,引入新的约束
<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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd">
</beans>
4、开启注解的扫描
<?xml version="1.0" encoding="UTF-8"?>
<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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<!-- 配置开启注解的扫描 -->
<!-- 扫描所有包 -->
<context:component-scan base-package="work.zhangdoudou"></context:component-scan>
<!-- 扫描属性上面的注解 -->
<!-- <context:annotation-config ></context:annotation-config> -->
</beans>