Tomcat 9 can't load spring boot application

2.2k views Asked by At

I am deploying a spring boot application to an existing Tomcat 9 instance. When tomcat tries to load the context, I get the following error:

org.apache.catalina.startup.HostConfig.deployWAR Error deploying web application archive 
    java.lang.IllegalStateException: Error starting child
            at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:720)
            at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:690)
            at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:706)
            at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:978)
            at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1848)
            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
            at java.util.concurrent.FutureTask.run(FutureTask.java:266)
            at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
            at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112)
            at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:773)
            at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:427)
            at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1620)
            at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:305)
            at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
            at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1151)
            at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1353)
            at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1357)
            at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1335)
            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
            at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
            at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
            at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
            at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
            at java.lang.Thread.run(Thread.java:748)
    Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/wservices]]
            at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440)
            at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198)
            at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:717)
            ... 25 more
    Caused by: java.lang.NoClassDefFoundError: org/glassfish/jersey/internal/l10n/LocalizableMessageFactory$ResourceBundleSupplier
            at org.glassfish.jersey.server.spring.SpringWebApplicationInitializer.onStartup(SpringWebApplicationInitializer.java:46)
            at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:172)
            at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5128)
            at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
            ... 26 more
    Caused by: java.lang.ClassNotFoundException: org.glassfish.jersey.internal.l10n.LocalizableMessageFactory$ResourceBundleSupplier
            at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1365)
            at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1188)

If I run the app by itself, it runs just fine using the embedded tomcat 9 engine.

Here's the spring dependencies I am using in pom file:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.2.5.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

        <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jersey</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <artifactId>logback-classic</artifactId>
                <groupId>ch.qos.logback</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-oracle</artifactId>
        <version>1.0.0.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>

Any help would be greatly appreciated.

3

There are 3 answers

1
pcroadkill On BEST ANSWER

After digging a bit more, the problem was that the Jersey version being pulled in was the incorrect one. The project was pulling in Jersey 2.6 which is the wrong version for Spring Boot 2.2.5. Jersey 2.6 (which has jersey-common 2.6 where the class in question is) does not include the org/glassfish/jersey/internal/l10n/LocalizableMessageFactory$ResourceBundleSupplierclass

Once I fixed the pom file, Tomcat loaded it correctly.

0
Oliver Marienfeld On

You‘ve packed a so-called über-jar, which contains every runtime dependency in one jar file. It also contains some classloading tweaks to get those dependency loaded from the jar. That will not work in Tomcat. You need to package as a web application archive.

You need to change

<project>
    ...
    <packaging>war</packaging>

See here for more detailed information.

1
Alien On

In Spring Boot, to create a WAR for deployment, we need 3 steps:

1.Extends SpringBootServletInitializer

2.Marked the embedded servlet container as provided.

3.Update packaging to war

See this link for steps in action.