0

I am migrating my Spring project into Spring Boot. However, when I am running the app I get this exception

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

I am using this inside my 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);
    }
}

Any ideas as to why I a might be running into this and how can I fix it?

Here is my gradle:

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'
dg428
  • 413
  • 6
  • 14
  • Why the dependencies are `compile` scope? See also http://snacktrace.com/artifacts/org.apache.tomcat/tomcat-coyote/8.0.8/org.apache.coyote.http11.AbstractHttp11JsseProtocol – StanislavL May 17 '17 at 13:55
  • You are using spring boot 1.5.3 which uses tomcat 8 but having dependencies to tomcat 6.Try removing `org.apache.tomcat` dependencies and keeping only spring-boot-starter-web dependency. – Issam El-atif May 17 '17 at 13:58
  • Thanks @StanislavL ! I was using the 6.0.53 since it was the latest here http://repo1.maven.org/maven2/org/apache/tomcat/coyote/ Did not realize they renamed it to tomcat-coyote – dg428 May 18 '17 at 07:09

2 Answers2

3

Remove:

@Bean
public EmbeddedServletContainerFactory servletContainer() {
    TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
    return factory;
}

Replace:

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application;
    }

with:

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(MyApplication.class);
    }

The spring-boot-starter-web artifact brings in spring-boot-starter-tomcat so no need to include it explicitly in your gradle file, please remove it too.

Remove:

compile 'org.apache.tomcat:catalina:6.0.53'
compile 'org.apache.tomcat:coyote:6.0.53'

Let spring-boot-starter-tomcat (which is a transitive dependency of spring-boot-starter-web) bring the supported version of Tomcat, 8.5.14 when using Spring Boot 1.5.3.RELEASE.

ootero
  • 3,235
  • 2
  • 16
  • 22
0

You need to update your maven dependencies, try to execute:

mvn install or mvn package

which will execute a complete maven life cycle.

you can also take a look here:

Maven: Command to update repository after adding dependency to POM

Community
  • 1
  • 1
Moshe Arad
  • 3,587
  • 4
  • 18
  • 33