我想将Spring启动与RestEasy集成。 我通过引用link
开始使用Paypal Springboot启动器我添加了上面链接中提到的paypal resteasy依赖。 但是在部署到Jboss服务器时,我收到的错误如下:
Caused by: java.lang.NoClassDefFoundError: org/jboss/resteasy/spi/NotImplementedYetException
at java.lang.Class.getDeclaredConstructors0(Native Method) [rt.jar:1.8.0_131]
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source) [rt.jar:1.8.0_131]
at java.lang.Class.getConstructor0(Unknown Source) [rt.jar:1.8.0_131]
at java.lang.Class.newInstance(Unknown Source) [rt.jar:1.8.0_131]
at org.jboss.as.web.deployment.ServletContainerInitializerDeploymentProcessor.loadSci(ServletContainerInitializerDeploymentProcessor.java:194)
at org.jboss.as.web.deployment.ServletContainerInitializerDeploymentProcessor.deploy(ServletContainerInitializerDeploymentProcessor.java:131)
有人可以建议我将Springboot与RestEasy集成的最佳方法吗?
答案 0 :(得分:0)
这些似乎是两个独立的问题:如何集成RESTEasy,以及如何部署到JBoss。
RESTEasy::您提到的用于RESTEasy的Paypal启动程序已转移到新家中。 https://github.com/resteasy/resteasy-spring-boot/blob/master/mds/USAGE.md 最新版本运行良好。 (我不知道自您使用的版本以来发生了什么变化。)
JBoss: 将自托管的Spring Boot应用程序转换为可在JBoss上运行的应用程序需要几个步骤,并且不清楚您已完成哪些更改。
1)在pom.xml中,将包装从jar更改为war。
2)同样在pom.xml中,从试图引入它的任何依赖项中排除spring-boot-starter-tomcat。通常这是spring-boot-starter-web,但是如果您使用resteasy-spring-boot -starter,您将排除在外。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
3)更改main
类,并将其扩展为SpringBootServletInitializer
。
4)同样在main
中重写configure
方法。 (某些文章省略了此步骤,这与确保正确扫描组件有关,因此可能有一些方法可以配置项目,因此它是可选的。)
public class NameOfMyMainClass extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(NameOfMyMainClass.class);
}
public static void main(String[] args) {
SpringApplication.run(NameOfMyMainClass.class, args);
}
}
这些步骤在此处详细说明:https://thepracticaldeveloper.com/2018/08/06/how-to-deploy-a-spring-boot-war-in-wildfly-jboss/
理论上这就是您所需要的。但是实际上,我从来没有使它起作用(Spring Boot 2.0.4,JBoss 7.1。)
第一个问题:Spring Boot 2显然需要JBoss7。直到我花了一些时间在JBoss 6上才知道这一点。 第二个问题:即使升级服务器后,我的JAX-RS Bean也无法正常工作。根据以下文章,JBoss 7.1.1不能完全集成,并且需要一些其他解决方法:https://ilya-murzinov.github.io/articles/spring-boot-jboss/
有些文章声称成功,但请注意,它们倾向于使用Wildfly,而不是JBoss。 (也有可能JBoss 7.0没有所有这些问题。)因此,如果您关注这些文章之一,请确保它们使用的是Spring Boot和JBoss版本。