Java – Jersey rest server: instantiating resource classes

The tutorial on Jersey rest server [1] said to Jersey small server:

When the servlet "selects the correct class and method", does it re instantiate the class every time? Or keep an instance of each resource class?

This seems important because if these resource classes refer to objects that store application wide state, these state objects will be re instantiated with the resource and the state data will not be stored correctly

[1] http://www.vogella.com/articles/REST/article.html#restjersey

Solution

Unless you annotate the class with @ singleton, Jersey will create a new instance of each class upon request

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

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>