如何配置Spring-Boot应用程序以继续使用RestEasy? [英] How configure Spring-Boot app to continue to use RestEasy?
问题描述
我有一个旧的Web应用程序(纯servlet,没有Spring),我想以胖子的身份运行.该应用程序提供了很多REST服务.我不想修改旧代码.
如何配置Spring-Boot应用程序以继续使用RestEasy?
I have an old web application (pure servlet, without Spring) that I want to run as fat-jar.
This app provides a lot of REST services. I don't want to modified old code.
How configure Spring-Boot app to continue to use RestEasy?
推荐答案
您可以使用RESTEasy Spring Boot启动程序.这是您的操作方式:
You can use RESTEasy Spring Boot starter. Here is how you do it:
添加POM依赖项
将下面的Maven依赖项添加到您的Spring Boot应用程序pom文件中.
Add the Maven dependency below to your Spring Boot application pom file.
<dependency>
<groupId>com.paypal.springboot</groupId>
<artifactId>resteasy-spring-boot-starter</artifactId>
<version>2.1.1-RELEASE</version>
<scope>runtime</scope>
</dependency>
注册JAX-RS应用程序类
只需将您的JAX-RS应用程序类(Application的子类)定义为Spring bean,它将被自动注册.请参见下面的示例.请参阅
Just define your JAX-RS application class (a subclass of Application) as a Spring bean, and it will be automatically registered. See the example below. See section JAX-RS application registration methods in How to use RESTEasy Spring Boot Starter for further information.
package com.test;
import org.springframework.stereotype.Component;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
@Component
@ApplicationPath("/sample-app/")
public class JaxrsApplication extends Application {
}
注册JAX-RS资源和提供者
只需将它们定义为Spring bean,它们将被自动注册.请注意,JAX-RS资源可以是单例的,也可以是请求范围的,而JAX-RS提供程序必须是单例的.
Just define them as Spring beans, and they will be automatically registered. Notice that JAX-RS resources can be singleton or request scoped, while JAX-RS providers must be singletons.
这篇关于如何配置Spring-Boot应用程序以继续使用RestEasy?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!