我正在将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 Class中使用它
@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'
答案 0 :(得分:2)
卸下:
@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
时,Tomcat
(8.5.14
的传递依赖关系)会带来Spring Boot
,1.5.3.RELEASE
的受支持版本
答案 1 :(得分:0)
您需要更新maven依赖项,尝试执行:
std::stringstream
或mvn install
将执行完整的maven生命周期。
你也可以看看这里:
Maven: Command to update repository after adding dependency to POM