[英]Spring Boot application works as standalone but class not found when deployed in Tomcat
[英]Spring Boot Tomcat Class Not Found
我正在将Spring项目迁移到Spring Boot中。 但是,当我运行应用程序时,出现此异常
19:09:31.059 [QUIET] [system.out] Caused by: java.lang.NoClassDefFoundError: org/apache/coyote/http11/AbstractHttp11JsseProtocol
19:09:31.059 [QUIET] [system.out] at java.lang.Class.getDeclaredMethods0(Native Method)
19:09:31.059 [QUIET] [system.out] at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
19:09:31.059 [QUIET] [system.out] at java.lang.Class.getDeclaredMethods(Class.java:1975)
19:09:31.059 [QUIET] [system.out] at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:613)
19:09:31.059 [QUIET] [system.out] at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:489)
19:09:31.059 [QUIET] [system.out] at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.buildPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:431)
19:09:31.060 [QUIET] [system.out] at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:397)
19:09:31.060 [QUIET] [system.out] ... 19 common frames omitted
19:09:31.060 [QUIET] [system.out] Caused by: java.lang.ClassNotFoundException: org.apache.coyote.http11.AbstractHttp11JsseProtocol
19:09:31.060 [QUIET] [system.out] at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
19:09:31.060 [QUIET] [system.out] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
19:09:31.060 [QUIET] [system.out] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
19:09:31.060 [QUIET] [system.out] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
19:09:31.060 [QUIET] [system.out] ... 26 common frames omitted
我在SpringApplication类中使用它
@SpringBootApplication
@ComponentScan(basePackages = "com.app")
public class MyApplication extends SpringBootServletInitializer {
@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
return factory;
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application;
}
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
关于为什么我可能会遇到此问题以及如何解决它的任何想法?
这是我的礼物:
compile('org.springframework.boot:spring-boot-starter-web')
compile group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat', version: '1.5.3.RELEASE'
compile 'org.apache.tomcat:catalina:6.0.53'
compile 'org.apache.tomcat:coyote:6.0.53'
去掉:
@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
return factory;
}
更换:
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application;
}
与:
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(MyApplication.class);
}
spring-boot-starter-web
工件引入了spring-boot-starter-tomcat
因此无需在gradle文件中明确包含它,也请删除它。
去掉:
compile 'org.apache.tomcat:catalina:6.0.53'
compile 'org.apache.tomcat:coyote:6.0.53'
让spring-boot-starter-tomcat
(是spring-boot-starter-web
的可传递依赖项)在使用Spring Boot
1.5.3.RELEASE
时带来受支持的Tomcat
8.5.14
版本。
您需要更新您的Maven依赖项,尝试执行:
mvn install
或mvn package
这将执行完整的Maven生命周期。
您也可以在这里看看:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.