Spring注解开发简要步骤

1、除spring基本包外还需要下载AOP包

spring-aop-4.2.4.RELEASE.jar

2、导入约束(最后两行)

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:contexnt="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-2.5.xsd">

3、指定注释自动扫描的包,自动注入包中有注解的类

<contexnt:component-scan base-package="org.helloworld"></contexnt:component-scan>

4、在扫描的类上加入注释标签

@Component、@Service等等

5、注入引用

@Autowired   自动注释
@Resource(name = "user") 指定名称

备注:也可以XML配置和注释混合使用

原文地址:https://www.cnblogs.com/gongxr/p/7954534.html