2011年11月22日——maven管理spring框架(重發)
阿新 • • 發佈:2019-01-03
#修改時打開了兩個網頁編輯,提交時出了衝突導致部落格一直處於【待稽核】狀態,故重發#
#在之前的工程之上,我們加入maven工具管理#
1.使用maven後就可以不用手動導包了,新增依賴maven會自動下載到本地倉庫
2.pom.xml是自動生成的,也可以自己建
3.只需要新增3個依賴即可
1.beans
2.context
3.core
<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>Springstudy</groupId> <artifactId>spring_study01</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>spring_study01</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-aop --> <!-- <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>5.1.1.RELEASE</version> </dependency> --> <!-- https://mvnrepository.com/artifact/org.springframework/spring-beans --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>5.1.1.RELEASE</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-context --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.1.1.RELEASE</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-core --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>5.1.1.RELEASE</version> </dependency> </dependencies> </project>
4.applicationContext.xml的約束要稍微增加幾項(如果你之前不加沒出錯的話就暫時不需要加,具體原因還在找),修改後如下,可自行對比;
若是在IDEA環境下,將此檔案放在resource下,並且要加這幾項,否則會出錯
<?xml version="1.0" encoding="UTF-8"?> <!-- <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/beans "> --> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"> <bean name="user" class="bean.User"></bean> </beans>
其他部分不需要改動。