maven搭建spring項目
阿新 • • 發佈:2017-05-31
pack http ces framework 分享 packaging 環境 lns mage
開發工具:MyEclipse2014版(jdk1.7)+Maven3.9。
新建Maven項目:
Step1:
Step2:
Step3:這裏選maven-archetype-webapp,因為後面的項目講解都是web項目。如果是純java項目,可以選擇 maven-archetype-quickstart。
Step4:
Step5:右鍵項目,build path,修改jdk運行環境。
到這裏,maven的web項目初建完畢。
修改:pom.xml
<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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.elstar</groupId> <artifactId>spring</artifactId><packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>spring Maven Webapp</name> <url>http://maven.apache.org</url> <!-- jar包版本控制 --> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <junit.version>4.12</junit.version> <spring.version>4.3.3.RELEASE</spring.version> </properties> <dependencies> <!-- junit支持 --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> <!-- spring支持 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <!-- spring測試支持 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${spring.version}</version> </dependency> </dependencies> <build> <finalName>spring</finalName> </build> </project>
添加spring配置文件:src/main/resources/applicationContext.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:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd"> </beans>
maven搭建spring項目