Spring开启注解配置


步骤:

  1. 首先要导入spring-aop-4.3.17.RELEASE.jar(使用maven添加)
  2. 在配置文件applicationContext.xml引入新的命名空间(即为xml约束)
  3. 开启注解扫描所要使用注解的类的包名
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 3        xmlns="http://www.springframework.org/schema/beans"
 4        xmlns:context="http://www.springframework.org/schema/context"
 5        xsi:schemaLocation="http://www.springframework.org/schema/beans
 6         http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
 7          http://www.springframework.org/schema/context
 8          http://www.springframework.org/schema/context/spring-context-4.3.xsd ">
 9 
10     <!-- base-package即为所要添加注解的类中的包名 -->
11     <context:component-scan base-package="po"></context:component-scan>
12 </beans>
  • 在javabean类上使用@Component("id名")
  • @Service("id名")         service层
  • @Controller("id名")     web层
  • @Repository("id名")   dao层


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM