SSM框架-搭建maven+web项目(idea)
鉴于配置环境踩的坑,做个记录
1、选择Maven--》选择java jdk--》勾选Create from archetype--》选择maven-archetype-webapp
2、填写GroupId(域名.公司名.项目名)、Artifacted(模块名)
3、选择本地maven解压的路径、配置文件
4、选择工作空间
5、创建成功,目录结构如下
6、在main下级目录新建两个文件夹java,resources
7、为了便于管理文件,在WEB-INF下级目录新建一个文件,命名jsp,再将index.jsp剪切进去,结果如下图所示
8、在resources中new一个XML文件(springmvc相关配置文件)
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xmlns:mvc="http://www.springframework.org/schema/mvc" 5 xsi:schemaLocation="http://www.springframework.org/schema/beans 6 http://www.springframework.org/schema/beans/spring-beans.xsd 7 http://www.springframework.org/schema/mvc 8 http://www.springframework.org/schema/mvc/spring-mvc.xsd"> 9 10 <mvc:annotation-driven/> 11 <mvc:default-servlet-handler/> 12 13 </beans>
pom.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 3 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 5 <modelVersion>4.0.0</modelVersion> 6 7 <groupId>com.dx.ssm</groupId> 8 <artifactId>client</artifactId> 9 <version>1.0-SNAPSHOT</version> 10 <packaging>war</packaging> 11 12 <name>client Maven Webapp</name> 13 <!-- FIXME change it to the project's website --> 14 <url>http://www.example.com</url> 15 16 <properties> 17 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 18 <maven.compiler.source>1.7</maven.compiler.source> 19 <maven.compiler.target>1.7</maven.compiler.target> 20 <spring.version>3.1.0.RELEASE</spring.version> 21 </properties> 22 23 <dependencies> 24 <dependency> 25 <groupId>junit</groupId> 26 <artifactId>junit</artifactId> 27 <version>4.11</version> 28 <scope>test</scope> 29 </dependency> 30 31 <!--spring核心包--> 32 <dependency> 33 <groupId>org.springframework</groupId> 34 <artifactId>spring-context</artifactId> 35 <version>${spring.version}</version> 36 </dependency> 37 <dependency> 38 <groupId>org.springframework</groupId> 39 <artifactId>spring-core</artifactId> 40 <version>${spring.version}</version> 41 </dependency> 42 <dependency> 43 <groupId>org.springframework</groupId> 44 <artifactId>spring-beans</artifactId> 45 <version>${spring.version}</version> 46 </dependency> 47 <dependency> 48 <groupId>org.springframework</groupId> 49 <artifactId>spring-context-support</artifactId> 50 <version>${spring.version}</version> 51 </dependency> 52 <dependency> 53 <groupId>org.springframework</groupId> 54 <artifactId>spring-aop</artifactId> 55 <version>${spring.version}</version> 56 </dependency> 57 <dependency> 58 <groupId>org.springframework</groupId> 59 <artifactId>spring-aspects</artifactId> 60 <version>${spring.version}</version> 61 </dependency> 62 <dependency> 63 <groupId>org.springframework</groupId> 64 <artifactId>spring-expression</artifactId> 65 <version>${spring.version}</version> 66 </dependency> 67 <dependency> 68 <groupId>org.springframework</groupId> 69 <artifactId>spring-jdbc</artifactId> 70 <version>${spring.version}</version> 71 </dependency> 72 <dependency> 73 <groupId>org.springframework</groupId> 74 <artifactId>spring-orm</artifactId> 75 <version>${spring.version}</version> 76 </dependency> 77 <dependency> 78 <groupId>org.springframework</groupId> 79 <artifactId>spring-tx</artifactId> 80 <version>${spring.version}</version> 81 </dependency> 82 <dependency> 83 <groupId>org.springframework</groupId> 84 <artifactId>spring-web</artifactId> 85 <version>${spring.version}</version> 86 </dependency> 87 <dependency> 88 <groupId>org.springframework</groupId> 89 <artifactId>spring-webmvc</artifactId> 90 <version>${spring.version}</version> 91 </dependency> 92 93 <!-- 数据库 --> 94 <dependency> 95 <groupId>mysql</groupId> 96 <artifactId>mysql-connector-java</artifactId> 97 <version>5.1.31</version> 98 </dependency> 99 <dependency> 100 <groupId>com.mchange</groupId> 101 <artifactId>c3p0</artifactId> 102 <version>0.9.5.2</version> 103 </dependency> 104 105 <!--mybatis--> 106 <dependency> 107 <groupId>org.mybatis</groupId> 108 <artifactId>mybatis</artifactId> 109 <version>3.4.6</version> 110 </dependency> 111 <dependency> 112 <groupId>org.mybatis</groupId> 113 <artifactId>mybatis-spring</artifactId> 114 <version>1.3.2</version> 115 </dependency> 116 117 <!-- 通用包--> 118 <dependency> 119 <groupId>commons-logging</groupId> 120 <artifactId>commons-logging</artifactId> 121 <version>1.2</version> 122 </dependency> 123 124 <!-- 其他 --> 125 <dependency> 126 <groupId>javax.servlet</groupId> 127 <artifactId>javax.servlet-api</artifactId> 128 <version>4.0.1</version> 129 <scope>provided</scope> 130 </dependency> 131 132 <dependency> 133 <groupId>com.alibaba</groupId> 134 <artifactId>fastjson</artifactId> 135 <version>1.2.47</version> 136 </dependency> 137 138 </dependencies> 139 140 </project>
9、选择工程--》鼠标右击--》选择build module
10、Tomcat部署
①选择Add Configuration
②点击左上角的“+”号,选择Tomcat Server--》local
③点击右侧“+”号,选择XXX:war,点OK
11、运行项目