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)文章
springboot反爬蟲組件kk-anti-reptile的使用方法
這篇文章主要介紹了springboot反爬蟲組件kk-anti-reptile的使用方法,幫助大家更好的利用spring boot反爬蟲,保護網(wǎng)站安全,感興趣的朋友可以了解下2021-01-01Java和Python現(xiàn)在都挺火,我應該怎么選?
這篇文章主要介紹了Java和Python現(xiàn)在都挺火,我應該怎么選?本文通過全面分析給大家做個參考,需要的朋友可以參考下2020-07-07Java線程間協(xié)作wait、notify和notifyAll詳解
這篇文章主要介紹了Java線程間協(xié)作wait、notify和notifyAll詳解,在 Java 中可以用 wait、notify 和 notifyAll 來實現(xiàn)線程間的通信,盡管關(guān)于wait和notify的概念很基礎(chǔ),它們也都是Object類的函數(shù),但用它們來寫代碼卻并不簡單,,需要的朋友可以參考下2023-10-10Java數(shù)據(jù)導出功能之導出Excel文件實例
這篇文章主要介紹了Java數(shù)據(jù)導出功能之導出Excel文件實例,本文給出了jar包的下載地址,并給出了導出Excel文件代碼實例,需要的朋友可以參考下2015-06-06Spring中ApplicationEvent事件機制源碼詳解
這篇文章主要介紹了Spring中ApplicationEvent事件機制源碼詳解,Spring中與事件有關(guān)的接口和類主要包括ApplicationEvent、ApplicationListener,下面來看一下Spring中事件的具體應用,需要的朋友可以參考下2023-09-09微信開發(fā)準備第二步 springmvc mybatis項目結(jié)構(gòu)搭建
這篇文章主要為大家詳細介紹了微信開發(fā)準備第二步,springmvc和mybatis項目結(jié)構(gòu)的搭建,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-04-04Elasticsearch算分優(yōu)化方案之rescore_query示例詳解
這篇文章主要為大家介紹了Elasticsearch算分優(yōu)化方案之rescore_query示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-08-08