使用eclipse搭建maven项目,默认为web2.3,这里详述下搭建过程中的问题,防止以后再次踩坑。。。
1:首先我们需要新建maven项目
2:创建完成后,需按照下图手动创建几个文件夹
Maven规定必须添加以下Source Folder:
src/main/resources
src/main/java
src/test/resources
src/test/java
3:修改默认jre为1.8
4:根据需要修改输出地址(非必须)
5:修改java为1.8,web为3.0,并指定webapp路径
第一次勾选dynamic web->apply->再次勾选->点击底部further configuration...->配置webapp路径为src/main/webapp
6:设置部署时的文件发布路径,删除test的两项,因为test是测试使用,并不需要部署。
设置将Maven的jar包发布到lib下。Add -> Java Build Path Entries -> Maven Dependencies -> Finish
7:添加tomcat依赖
8:Maven引入需要的JAR包并修改maven配置使用jdk1.8
4.0.0
com.cgd
new
war
0.0.1-SNAPSHOT
new Maven Webapp
http://maven.apache.org
4.2.1.RELEASE
3.2.8
1.7.12
1.2.17
junit
junit
4.11
test
org.springframework
spring-test
${srping.version}
org.springframework
spring-core
${srping.version}
org.springframework
spring-oxm
${srping.version}
org.springframework
spring-tx
${srping.version}
org.springframework
spring-jdbc
${srping.version}
org.springframework
spring-aop
${srping.version}
org.springframework
spring-context
${srping.version}
org.springframework
spring-context-support
${srping.version}
org.springframework
spring-expression
${srping.version}
org.springframework
spring-orm
${srping.version}
org.springframework
spring-web
${srping.version}
org.springframework
spring-webmvc
${srping.version}
org.mybatis
mybatis
${mybatis.version}
org.mybatis
mybatis-spring
1.2.2
mysql
mysql-connector-java
5.1.35
commons-dbcp
commons-dbcp
1.4
jstl
jstl
1.2
log4j
log4j
${log4j.version}
org.slf4j
slf4j-api
${slf4j.version}
org.slf4j
slf4j-log4j12
${slf4j.version}
org.apache.tomcat.embed
tomcat-embed-websocket
8.0.23
provided
org.springframework
spring-websocket
${srping.version}
com.thetransactioncompany
cors-filter
2.4
new
org.apache.maven.plugins
maven-compiler-plugin
1.8
9:上述操作后update操作maven,如果jdk system会被复原到原来的1.5版本,可以修改org.eclipse.wst.common.project.facet.core.xml文件内容指定版本号
10:修改web.xml文件版本信息并引入相关MVC配置
CORS
com.thetransactioncompany.cors.CORSFilter
cors.allowOrigin
*
cors.supportedMethods
GET, POST, HEAD, PUT, DELETE,OPTIONS
cors.supportedHeaders
Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With
cors.exposedHeaders
Set-Cookie
cors.supportsCredentials
true
CORS
/*
contextConfigLocation
classpath*:*applicationContext*.xml
org.springframework.web.context.ContextLoaderListener
encodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
forceEncoding
true
encodingFilter
/*
springMVC
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath*:/spring-mvc*.xml
1
springMVC
/
index.jsp
index.html
11:update maven后就能看的不再报错了
注:
文章参考:https://www.cnblogs.com/flycatnet/p/5917692.html
指定maven使用jdk版本参考:https://blog.csdn.net/baofeidyz/article/details/52053879