Spring項目XML文件使用小結(jié)
1 項目pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.yang</groupId>
<artifactId>spring-study</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>spring-01-ioc1</module>
<module>spring-02-hellpspring</module>
<module>spring-04-di</module>
<module>spring-06-autowired</module>
<module>spring-07-annotation</module>
</modules>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.1.4.RELEASE</version>
</dependency>
</dependencies>
</project>
···2 項目初始IOC容器
```xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- more bean definitions go here -->
</beans>
···3 項目需要自動裝配
```xml
<?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
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config/>
<bean id="dog" class="com.yang.pojo.Dog"></bean>
<bean id="cat" class="com.yang.pojo.Cat"></bean>
<bean id = "people" class="com.yang.pojo.People">
<property name="cat" ref="cat"/>
<property name="dog" ref="dog"/>
<property name="name" value="張3"/>
</bean>
</beans>增加的點:
1 xmlns:context="http://www.springframework.org/schema/context"等等頭文件
2 context:annotation-config/
4 項目需要注解
<?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"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
https://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- 指定要掃描的包,包下面的注解才能夠生效-->
<context:component-scan base-package="com.yang.pojo"/>
<!-- 注解驅(qū)動-->
<context:annotation-config/>
</beans>增加的點:
<context:component-scan base-package=“com.yang.pojo”/>
https://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
到此這篇關(guān)于Spring項目XML文件使用常見介紹的文章就介紹到這了,更多相關(guān)Spring項目XML文件使用內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Mybatis中如何設(shè)置sqlSession自動提交
在MyBatis中,默認(rèn)情況下,獲取的SqlSession對象不會自動提交事務(wù),這意味著在進(jìn)行更新、刪除或插入等操作后,需要顯式調(diào)用commit方法來提交事務(wù),但是,可以在獲取SqlSession時通過將openSession方法的參數(shù)設(shè)置為true2024-09-09
OpenFeign調(diào)用服務(wù)請求頭丟失Token的解決
這篇文章主要介紹了OpenFeign調(diào)用服務(wù)請求頭丟失Token的解決方法,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-06-06
Spring Boot 數(shù)據(jù)校驗@Valid+統(tǒng)一異常處理的實現(xiàn)
這篇文章主要介紹了Spring Boot 數(shù)據(jù)校驗@Valid+統(tǒng)一異常處理的實現(xiàn),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-04-04
SpringBoot整合FastDFS中間件實現(xiàn)文件分布管理
FastDFS是一個開源的輕量級分布式文件系統(tǒng),它對文件進(jìn)行管理,功能包括:文件存儲、文件同步、文件上傳、文件下載等,解決了大容量存儲和負(fù)載均衡的問題,本文介紹了SpringBoot整合FastDFS中間件實現(xiàn)文件分布管理,需要的朋友可以參考下2024-08-08
帶你了解Java數(shù)據(jù)結(jié)構(gòu)和算法之無權(quán)無向圖
這篇文章主要為大家介紹了Java數(shù)據(jù)結(jié)構(gòu)和算法之無權(quán)無向圖?,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助2022-01-01
Spring集成MyBatis?及Aop分頁的實現(xiàn)代碼
這篇文章主要介紹了Spring集成MyBatis?及Aop分頁的實現(xiàn),本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-04-04

