Spring Boot EurekaClient 应用程序无法在外部 TC 服务器中运行
Spring Boot EurekaClient application is not working in external TC server
我有一个 Spring 引导恢复服务。最近,我将其更新为 Discovery Client,以利用 spring 云提供的自动发现和路由。当来自 STS 的 运行 时,该服务工作正常。但是,当我将它部署到外部 TC 服务器时,它并没有开始在 catalina 日志中抛出以下错误。
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
我在 pom 中有以下与此相关的依赖项
<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 -->
我尝试添加以下依赖项 also.But,但没有成功。请推荐。
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.11</version>
</dependency>
编辑:
申请class
@SpringBootApplication
@EnableDiscoveryClient
public class Application {
public static void main(String[] args) {
SpringApplication app = new SpringApplication(Application.class);
app.run(args);
}
}
控制器实现
@RestController
@RequestMapping("/api")
public class ResourceController {
@RequestMapping(value="/test", method = RequestMethod.GET)
public String test(){
return "Service is Alive";
}
}
此类错误主要导致以下任一情况:-
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.
在你的情况下,声明说 "org.glassfish.jersey.server.ResourceConfig" 所以你应该包括来自项目 "org.glassfish.jersey" 的那个。请试试这个:-
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.22</version>
</dependency>
我有一个 Spring 引导恢复服务。最近,我将其更新为 Discovery Client,以利用 spring 云提供的自动发现和路由。当来自 STS 的 运行 时,该服务工作正常。但是,当我将它部署到外部 TC 服务器时,它并没有开始在 catalina 日志中抛出以下错误。
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
我在 pom 中有以下与此相关的依赖项
<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 -->
我尝试添加以下依赖项 also.But,但没有成功。请推荐。
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.11</version>
</dependency>
编辑: 申请class
@SpringBootApplication
@EnableDiscoveryClient
public class Application {
public static void main(String[] args) {
SpringApplication app = new SpringApplication(Application.class);
app.run(args);
}
}
控制器实现
@RestController
@RequestMapping("/api")
public class ResourceController {
@RequestMapping(value="/test", method = RequestMethod.GET)
public String test(){
return "Service is Alive";
}
}
此类错误主要导致以下任一情况:-
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.
在你的情况下,声明说 "org.glassfish.jersey.server.ResourceConfig" 所以你应该包括来自项目 "org.glassfish.jersey" 的那个。请试试这个:-
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.22</version>
</dependency>