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