Search code examples
javaspringspring-bootspring-cloudservice-discovery

Spring Boot EurekaClient application is not working in external TC server


I have a Spring Boot rest service. Recently, I have updated it as Discovery Client to leverage auto discovery and routing provided by spring cloud. The service is working fine when it is running from STS. But, while I'm deploying it to external TC server, it is not starting throwing the below error at catalina log.

24-Sep-2015 04:42:49.945 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal Error during ServletContainerInitializer processing
 javax.servlet.ServletException: Failed to instantiate WebApplicationInitializer class
    at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:160)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5479)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:649)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1083)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1880)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:483)
    at java.util.concurrent.FutureTask.run(FutureTask.java:274)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1177)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
    at java.lang.Thread.run(Thread.java:795)
Caused by: java.lang.NoClassDefFoundError: org.glassfish.jersey.server.ResourceConfig
    at java.lang.J9VMInternals.verifyImpl(Native Method)
    at java.lang.J9VMInternals.verify(J9VMInternals.java:94)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:169)
    at java.lang.J9VMInternals.newInstanceImpl(Native Method)
    at java.lang.Class.newInstance(Class.java:1712)
    at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:157)
    ... 12 more
Caused by: java.lang.ClassNotFoundException: org.glassfish.jersey.server.ResourceConfig
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
    ... 18 more

I have below dependencies in pom related to this

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.1.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>
.
.
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>
<!-- For Eureka dependency -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-eureka</artifactId>
    <version>1.0.3.RELEASE</version>
    </dependency>
<!-- End of Eureka dependency -->

I have tried adding below depency also.But, no luck. Please suggest.

<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-server</artifactId>
    <version>1.11</version>
</dependency>

EDIT: Application class

@SpringBootApplication
@EnableDiscoveryClient
public class Application {
 public static void main(String[] args) {
         SpringApplication app = new SpringApplication(Application.class);
         app.run(args);
    }
}

Controller implementation

@RestController
@RequestMapping("/api")
public class ResourceController {
@RequestMapping(value="/test",  method = RequestMethod.GET)
    public String test(){
        return "Service is Alive";
    }
}

Solution

  • Such error mostly result in either of these cases :-

    a) Respective library is missing 
    b) The version of library is old and do not hold respective implementation needed.
    c) There is more than one version of library available in classpath and app gets stuck in deciding which to use.
    

    In your case the statement says "org.glassfish.jersey.server.ResourceConfig" so you should be including the one from project "org.glassfish.jersey". Pls try this:-

    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-server</artifactId>
        <version>2.22</version>
    </dependency>