首页 > 编程语言 > 详细

Spring注解开发简要步骤

时间:2017-12-02 16:48:00      阅读:237      评论:0      收藏:0      [点我收藏+]

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配置和注释混合使用

 

Spring注解开发简要步骤

原文:http://www.cnblogs.com/gongxr/p/7954534.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!