maven:pom.xml 搭建spring框架基本配置
1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 3 <modelVersion>4.0.0</modelVersion> 4 <groupId>luowuhui</groupId> 5 <artifactId>luowuhui1106_springAnnotation</artifactId> 6 <version>0.0.1-SNAPSHOT</version> 7 <packaging>war</packaging> 8 <properties> 9 <!-- 设定版本信息 变量 来替代 具体值 --> 10 <servlet-version>3.1.0</servlet-version> 11 <spring-version>4.2.8.RELEASE</spring-version> 12 </properties> 13 <dependencies> 14 <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api --> 15 <dependency> 16 <groupId>javax.servlet</groupId> 17 <artifactId>javax.servlet-api</artifactId> 18 <!-- 引用版本信息变量 --> 19 <version>${servlet-version}</version> 20 <scope>provided</scope> 21 </dependency> 22 23 <!-- spring核心容器功能的依赖包 spring-context包会自动依赖其他spring的核心功能包 --> 24 <!-- https://mvnrepository.com/artifact/org.springframework/spring-context --> 25 <dependency> 26 <groupId>org.springframework</groupId> 27 <artifactId>spring-context</artifactId> 28 <version>${spring-version}</version> 29 </dependency> 30 <dependency> 31 <groupId>junit</groupId> 32 <artifactId>junit</artifactId> 33 <version>4.12</version> 34 </dependency> 35 <dependency> 36 <groupId>mysql</groupId> 37 <artifactId>mysql-connector-java</artifactId> 38 <version>5.1.38</version> 39 </dependency> 40 <!-- https://mvnrepository.com/artifact/com.mchange/c3p0 --> 41 <dependency> 42 <groupId>com.mchange</groupId> 43 <artifactId>c3p0</artifactId> 44 <version>0.9.5.2</version> 45 </dependency> 46 <!-- https://mvnrepository.com/artifact/javax.servlet/jstl --> 47 <dependency> 48 <groupId>javax.servlet</groupId> 49 <artifactId>jstl</artifactId> 50 <version>1.2</version> 51 </dependency> 52 <!-- https://mvnrepository.com/artifact/org.springframework/spring-test --> 53 <dependency> 54 <groupId>org.springframework</groupId> 55 <artifactId>spring-test</artifactId> 56 <version>4.2.8.RELEASE</version> 57 <scope>test</scope> 58 </dependency> 59 </dependencies> 60 <!-- build 构建配置 --> 61 <build> 62 <!-- 插件 maven中可以集成各种插件,通过集成插件的方式,将项目需要用到的环境通过maven插件来实现 --> 63 <plugins> 64 <!-- maven编译插件,将java文件编译成字节码文件 下面设置了1.8的jdk --> 65 <plugin> 66 <artifactId>maven-compiler-plugin</artifactId> 67 <version>3.5.1</version> 68 <configuration> 69 <source>1.8</source> 70 <target>1.8</target> 71 </configuration> 72 </plugin> 73 <!-- 打war包的插件,打成war包后可以直接部署到服务器上 --> 74 <plugin> 75 <artifactId>maven-war-plugin</artifactId> 76 <version>2.6</version> 77 <configuration> 78 <failOnMissingWebXml>false</failOnMissingWebXml> 79 </configuration> 80 </plugin> 81 <!-- maven会自动的集成tomcat插件,通过内置的tomcat来搭建项目中的web容器环境 在maven构建项目的时候 run as-> 82 maven build 会在当前项目工程位置 临时构建一个tomcat tomcat7-maven-plugin对应tomcat版本 maven插件集成tomcat管理环境步骤: 83 1.pom中添加tomcat插件配置 2.通过run as-> maven build->tomcat7:run 来启动maven构建,maven会自动启动刚才配置好的tomcat 84 3.如果缺少依赖包,则添加依赖包,重新构建项目即可 --> 85 <plugin> 86 <groupId>org.apache.tomcat.maven</groupId> 87 <artifactId>tomcat7-maven-plugin</artifactId> 88 <version>2.2</version> 89 <!-- 设置tomcat --> 90 <configuration> 91 <!-- 设置默认编码 --> 92 <charset>UTF-8</charset> 93 <!-- 设置端口号 --> 94 <port>8080</port> 95 <!-- 设置应用路径 设置成/的意思就是将当前的项目直接部署到maven中的tomcat的webapp下, 96 可以省略项目名访问资源 --> 97 <path>/</path> 98 </configuration> 99 </plugin> 100 </plugins> 101 </build> 102 </project>
使用要求;配置了tomcat7
启动方式:tomcat7:run