Spring我爱编程

spring 注解开发准备

2018-05-28  本文已影响14人  DouDouZH

注解:

1、导入jar包

红色框为新添加jar包


image.png
2、创建类、创建方法
3、创建spring配置文件,引入约束

(1)引入bean约束
(2)做springioc注解开发,引入新的约束


image.png
image.png
<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>
上一篇 下一篇

猜你喜欢

热点阅读