最近在做项目的迁移重构工作,将原来的ssh 框架的web 项目改造成spring boot 的项目,放到云上docker容器中运行,在改造的过程中一路坎坷,遇到了各种坑,各种奇怪的问题,首先我们来说一下本地启动没问题,服务器启动访问jsp 报404 的问题。
我的pom.xml 文件如下:
4.0.0
com.tservice
cc
1.0-SNAPSHOT
jar
Maven Webapp
http://maven.apache.org
org.springframework.boot
spring-boot-starter-parent
1.5.17.RELEASE
1.8
2.4.3
4.3.11.Final
Edgware.SR5
UTF-8
jar
jar
0.9.0
system
${basedir}/src/main/webapp/WEB-INF/lib/jar.jar
org.apache.tomcat.embed
tomcat-embed-jasper
9.0.17
provided
javax.servlet
jstl
org.springframework.boot
spring-boot-starter-actuator
org.springframework.boot
spring-boot-starter-thymeleaf
org.springframework.boot
spring-boot-starter-web
org.springframework.cloud
spring-cloud-starter-openfeign
org.springframework.boot
spring-boot-devtools
runtime
mysql
mysql-connector-java
runtime
org.springframework.boot
spring-boot-starter-test
test
com.codahale.metrics
metrics-core
3.0.2
org.mybatis.spring.boot
mybatis-spring-boot-starter
2.0.0
com.alibaba
druid
1.1.14
org.projectlombok
lombok
1.18.6
provided
com.google.code.gson
gson
2.8.5
org.springframework.boot
spring-boot-starter-data-redis
org.springframework.boot
spring-boot-starter-data-jpa
1.4.0.RELEASE
org.hibernate
hibernate-core
org.apache.httpcomponents
httpclient
4.5.6
org.hibernate
hibernate-core
${hibernate.version}
jboss-logging
org.jboss.logging
hibernate-jpa-2.0-api
org.hibernate.javax.persistence
jboss-transaction-api_1.1_spec
org.jboss.spec.javax.transaction
org.hibernate
hibernate-ehcache
${hibernate.version}
org.hibernate
hibernate-c3p0
${hibernate.version}
com.netflix.feign
feign-gson
8.18.0
org.springframework.cloud
spring-cloud-dependencies
${spring-cloud.version}
pom
import
cc
src/main/resources
**/**
src/main/webapp
META-INF/resources
**/**
org.apache.maven.plugins
maven-compiler-plugin
1.8
UTF-8
org.springframework.boot
spring-boot-maven-plugin
1.4.2.RELEASE
true
true
com.tservice.BootstrapApplication
repackage
org.apache.maven.plugins
maven-surefire-plugin
2.22.1
${argLine} -Djdk.net.URLClassPath.disableClassPathURLCheck=true
org.jacoco
jacoco-maven-plugin
0.8.2
false
${basedir}/target
default-prepare-agent
prepare-agent
default-report
report
配置文件
spring:
application:
name: cc
mvc:
view:
prefix: /
suffix: .jsp
thymeleaf:
cache: false
enabled: false
messages:
basename: i18n.messages
encoding: UTF-8
server:
port: 8080
logging:
level:
root: INFO
mybatis:
configuration:
mapUnderscoreToCamelCase: true
pagehelper:
helper-dialect: mysql
reasonable: true
support-methods-arguments: true
params: count=countSql
auto-runtime-dialect: true
hystrix:
command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds: 30000
数据库配置这里就不贴出来了,本地利用eclipse运行正常,没有任何报错,正常也访问,然后打成jar 包丢到服务器上运行 java -jar cc.jar
结果报错:
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:950)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:872)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
… 6 common frames omitted
Caused by: java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[]]
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:942)
… 8 common frames omitted
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
… 6 common frames omitted
Caused by: java.lang.IllegalArgumentException: Unable to create an instance of type [com.sun.faces.util.ReflectionUtils R e f l e c t i o n U t i l s L i s t e n e r ] a t o r g . a p a c h e . c a t a l i n a . c o r e . A p p l i c a t i o n C o n t e x t . a d d L i s t e n e r ( A p p l i c a t i o n C o n t e x t . j a v a : 1144 ) a t o r g . a p a c h e . c a t a l i n a . c o r e . A p p l i c a t i o n C o n t e x t F a c a d e . a d d L i s t e n e r ( A p p l i c a t i o n C o n t e x t F a c a d e . j a v a : 660 ) a t o r g . a p a c h e . j a s p e r . s e r v l e t . J a s p e r I n i t i a l i z e r . o n S t a r t u p ( J a s p e r I n i t i a l i z e r . j a v a : 90 ) a t o r g . a p a c h e . c a t a l i n a . c o r e . S t a n d a r d C o n t e x t . s t a r t I n t e r n a l ( S t a n d a r d C o n t e x t . j a v a : 5245 ) a t o r g . a p a c h e . c a t a l i n a . u t i l . L i f e c y c l e B a s e . s t a r t ( L i f e c y c l e B a s e . j a v a : 150 ) . . . 6 c o m m o n f r a m e s o m i t t e d C a u s e d b y : j a v a . l a n g . C l a s s N o t F o u n d E x c e p t i o n : c o m . s u n . f a c e s . u t i l . R e f l e c t i o n U t i l s ReflectionUtilsListener] at org.apache.catalina.core.ApplicationContext.addListener(ApplicationContext.java:1144) at org.apache.catalina.core.ApplicationContextFacade.addListener(ApplicationContextFacade.java:660) at org.apache.jasper.servlet.JasperInitializer.onStartup(JasperInitializer.java:90) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5245) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 6 common frames omitted Caused by: java.lang.ClassNotFoundException: com.sun.faces.util.ReflectionUtils ReflectionUtilsListener]atorg.apache.catalina.core.ApplicationContext.addListener(ApplicationContext.java:1144)atorg.apache.catalina.core.ApplicationContextFacade.addListener(ApplicationContextFacade.java:660)atorg.apache.jasper.servlet.JasperInitializer.onStartup(JasperInitializer.java:90)atorg.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5245)atorg.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)...6commonframesomittedCausedby:java.lang.ClassNotFoundException:com.sun.faces.util.ReflectionUtilsReflectionUtilsListener
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedWebappClassLoader.loadClass(TomcatEmbeddedWebappClassLoader.java:52)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1137)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:546)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:527)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:150)
at org.apache.catalina.core.ApplicationContext.addListener(ApplicationContext.java:1126)
… 10 common frames omitted
这个就比较郁闷了,本地没有任何报错,丢服务器上就出现问题,应该是缺少jar 包的原因,百度了一下,竟然没有任何有价值的信息,然后再一篇国外的网址张看到这样一篇信息
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190719135545396.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTQ1MjAwMDY=,size_16,color_FFFFFF,t_70)
地址我也附一下:https://stackoverflow.com/questions/29819800/java-lang-classnotfoundexception-com-sun-faces-util-reflectionutilsreflectionu
在pom中引入如下两个jar包,后程序正常启动,访问也正常
jsf-impl jsf-impl 0.9.0 system ${basedir}/src/main/webapp/WEB-INF/lib/jsf-impl.jar
jsf-api
jsf-api
0.9.0
system
${basedir}/src/main/webapp/WEB-INF/lib/jsf-api.jar
总结一下,有几点需要注意一下:
1. spring-boot-maven-plugin 打包插件版本非常重要,不能高于1.4.2.RELEASE版本
2. 打jar包后的jsp文件路径是否正确
src/main/webapp
META-INF/resources
**/**
3. 配置文件中的jsp 配置
spring:
mvc:
view:
prefix: /
suffix: .jsp