Jersey REST Server: instantiating resource classes

后端 未结 2 491
傲寒
傲寒 2020-12-29 12:24

A tutorial on the Jersey REST server [1] says of the Jersey servlet:

This servlet analyzes the incoming HTTP request and selects the correct class and

相关标签:
2条回答
  • 2020-12-29 12:46

    Jersey will establish a new instance of each class per request unless you annotate the class with @Singleton.

    See: https://jersey.java.net/documentation/latest/jaxrs-resources.html#d0e2331

    0 讨论(0)
  • 2020-12-29 12:55

    Actually according to this post default annotation type is change from singleton to per-request. Which means before one instance is used for every request but now create new class object for per-request. If you postwant to change it you can use resourceFactory annotation.

    @Target({ElementType.TYPE})
    @Retention(RetentionPolicy.RUNTIME)
    @Documented
    @ResourceFactory(SingletonProvider.class)
    public @interface Singleton {}
    

    Also you can check this link for com.sun.jersey.spi.resource JavaDoc

    0 讨论(0)
提交回复
热议问题