Registering a provider programmatically in jersey which implements exceptionmapper

前端 未结 3 1851
北恋
北恋 2021-01-05 13:56

How do I register my provider programmatically in jersey which implements the Exceptionmapper provided by jersey API? I don\'t want to use @Provider annotation and want to r

3条回答
  •  难免孤独
    2021-01-05 14:52

    I'm guessing you don't have a ResourceConfig, since you seem to not be sure how to use it. For one, it is not required. If you do use it, it should be it's own separate class. There you can register the mapper.

    public class AppConfig extends ResourceConfig {
        public AppConfig() {
            register(new MyProvider());
        }
    }
    

    But you are probably using a web.xml. In which case, you can register the provider, with the following

    
        MyApplication
        org.glassfish.jersey.servlet.ServletContainer
        
            jersey.config.server.provider.classnames
            
                org.foo.providers.MyProvider
            
        
    
    

    Have a look at Application Deployment and Runtime Environments for more information on different deployment models. There are a few different ways to deploy applications. You can even mix and match (web.xml and ResourceConfig).

提交回复
热议问题