maven搭建spring项目(图文教程)
程序员文章站
2024-02-16 13:29:34
开发工具:myeclipse2014版(jdk1.7)+maven3.9。
新建maven项目:
step1:
step2:
step3:这里选maven-...
开发工具: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项目(图文教程)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。