restful service interface with jersey

前端 未结 5 999
日久生厌
日久生厌 2020-12-11 07:44

Can I create a restful service with interface and implementation class?

If so, will all JAX-RS related imports go into the interface?

I am using jersey2.4 an

5条回答
  •  执笔经年
    2020-12-11 08:22

    In the class ResourceConfig, there is a constructor like this

    ResourceConfig(Class... classes)
    

    The constructor create a new resource configuration initialized with a given set of resource/provider classes.
    So you can extend ResourceConfig to register the implementation class.

    public class RestConfig extends ResourceConfig {
    
        public RestConfig() {
            // register the implementation class
            super(MyServiceImpl.class);
        }
    
    }
    

    Then, configure web.xml.

    
        Scivantage REST Service
        org.glassfish.jersey.servlet.ServletContainer
        
            javax.ws.rs.Application
            
            foo.bar.RestConfig
        
        1
    
    

    But the simplest way is that register the implementation class in web.xml.

    
        Scivantage REST Service
        org.glassfish.jersey.servlet.ServletContainer
        
            jersey.config.server.provider.classnames
            
            foo.bar.impl.MyServiceImpl
        
        1
    
    

提交回复
热议问题