1.Spring的注解开发

注解开发流程:
1)Spring的注解开发除了四个核心jar还需要aop包的支持,引入pring-aop-4.3.2.RELEASE.jar.
2)在配置文件中引入约束schema.
3)开启注解扫描.


1.注解约束schema:spring-context.xsd配置.

在配置文件中需要引入注解的约束:
   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd

原文如下:


41.2.8 the context schema

The context tags deal with ApplicationContext configuration that relates to plumbing - that is, not usually beans that are important to an end-user but rather beans that do a lot of grunt work in Spring, such as BeanfactoryPostProcessors. The following snippet references the correct schema so that the tags in the context namespace are available to you.

<?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.xsd"> <!-- bean definitions here -->

</beans>

2.开启注解扫描:

    <!-- 开启注解扫描 
        到包里面扫描类、方法、属性上面是否有注解 (开发一般建议使用)
    -->
    <context:component-scan base-package="cn.com.yves"></context:component-scan>

    <!-- 
        只扫描属性上面的注解 
     -->
    <!-- <context:annotation-config></context:annotation-config> -->

注意:

  • 1.在类上使用注解的时候,默认的是调用的无参构造方法来实例化对象的.
  • 2如果是多个不同的包可以在配置多个值在base-package属性中,比如配置扫描cn.com.yves和cn.com.utils包下java类,中间用逗号, 隔开<context:component-scan base-package="cn.com.yves,cn.com.utils"></context:component-scan>
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值