How configure Spring-Boot app to continue to use RestEasy?

后端 未结 2 817
独厮守ぢ
独厮守ぢ 2021-01-05 10:13

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.

2条回答
  •  走了就别回头了
    2021-01-05 10:27

    You can use RESTEasy Spring Boot starter. Here is how you do it:

    Adding POM dependency

    Add the Maven dependency below to your Spring Boot application pom file.

    
       com.paypal.springboot
       resteasy-spring-boot-starter
       2.1.1-RELEASE
       runtime
    
    

    Registering JAX-RS application classes

    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 {
    }
    

    Registering JAX-RS resources and providers

    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.

    Further information at the project GitHub page.

提交回复
热议问题