最近在做项目的迁移重构工作,将原来的ssh 框架的web 项目改造成spring boot 的项目,放到云上docker容器中运行,在改造的过程中一路坎坷,遇到了各种坑,各种奇怪的问题,首先我们来说一下本地启动没问题,服务器启动访问jsp 报404 的问题。
我的pom.xml 文件如下:
4.0.0
<!-- maven的坐标,唯一标识了一个项目 -->
<groupId>com.tservice</groupId>
<artifactId>cc</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<!--项目的名称和主页URL, Maven产生的文档用 -->
<name> Maven Webapp</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.17.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<!--以值替代名称,整个POM中使用 -->
<properties>
<java.version>1.8</java.version>
<ehcache.version>2.4.3</ehcache.version>
<hibernate.version>4.3.11.Final</hibernate.version>
<spring-cloud.version>Edgware.SR5</spring-cloud.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<!-- 依赖列表 -->
<dependencies>
<dependency>
<groupId>jar</groupId>
<artifactId>jar</artifactId>
<version>0.9.0</version>
<scope>system</scope>
<systemPath>${basedir}/src/main/webapp/WEB-INF/lib/jar.jar
</systemPath>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.tomcat.embed/tomcat-embed-jasper -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>9.0.17</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<!-- <version>1.2</version> -->
</dependency>
<!--spring cloud 依赖组件-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!-- 移除嵌入式tomcat插件 -->
<!-- <exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions> -->
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.codahale.metrics/metrics-core -->
<dependency>
<groupId>com.codahale.metrics</groupId>
<artifactId>metrics-core</artifactId>
<version>3.0.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring-boot-starter -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.14</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.6</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-websocket -->
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
<version>2.1.3.RELEASE</version>
</dependency> -->
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!--<!– https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa –>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>1.4.0.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
<exclusions>
<exclusion>
<artifactId>jboss-logging</artifactId>
<groupId>org.jboss.logging</groupId>
</exclusion>
<exclusion>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<groupId>org.hibernate.javax.persistence</groupId>
</exclusion>
<exclusion>
<artifactId>jboss-transaction-api_1.1_spec</artifactId>
<groupId>org.jboss.spec.javax.transaction</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-ehcache -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-c3p0 -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-entitymanager -->
<!-- <dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency> -->
<dependency>
<groupId>com.netflix.feign</groupId>
<artifactId>feign-gson</artifactId>
<version>8.18.0</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<!--构建项目元素 -->
<build>
<finalName>cc</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/**</include>
</includes>
</resource>
<resource>
<directory>src/main/webapp</directory>
<targetPath>META-INF/resources</targetPath>
<includes>
<include>**/**</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.4.2.RELEASE</version>
<configuration>
<fork>true</fork>
<includeSystemScope>true</includeSystemScope>
<mainClass>com.tservice.BootstrapApplication</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<argLine>${argLine} -Djdk.net.URLClassPath.disableClassPathURLCheck=true</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2</version>
<configuration>
<skip>false</skip>
<outputDirectory>${basedir}/target</outputDirectory>
</configuration>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
配置文件
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
<dependency>
<groupId>jsf-api</groupId>
<artifactId>jsf-api</artifactId>
<version>0.9.0</version>
<scope>system</scope>
<systemPath>${basedir}/src/main/webapp/WEB-INF/lib/jsf-api.jar
</systemPath>
</dependency>
总结一下,有几点需要注意一下:
1. spring-boot-maven-plugin 打包插件版本非常重要,不能高于1.4.2.RELEASE版本
2. 打jar包后的jsp文件路径是否正确
<resource>
<directory>src/main/webapp</directory>
<targetPath>META-INF/resources</targetPath>
<includes>
<include>**/**</include>
</includes>
</resource>
3. 配置文件中的jsp 配置
spring:
mvc:
view:
prefix: /
suffix: .jsp