@PostConstruct method called all the time in the service of Jersey

Hi, I am using GigaSpaces XAP, which mainly uses Spring and ApplicationContext to do all this init and config, etc. At some point in time during the loading of the web application, a “cache” or what they call a space proxy is created and accessed through the ServletContext. This proxy server allows you to write and read to the cluster cache.

So, first I had to get space for each REST method. So that...

@GET public String myMethod () {space = (GigaSpace) context.getAttribute ("mySpace"); space.write (new HelloWorld ()); space.read (....); etc ... return "Hello World!"; }

Since the space itself is thread safe, I was instructed by the GigaSpaces guys to search the space once when initializing my "application", so I can save on finding space.

So, I looked at @PostConstrust where I did ...

@PostConstruct public void init () {space = (GigaSpace) context.getAttribute ("mySpace"); }

But it seems like this method is called on every request I make! Does this mean that my REST service is being created for every request I make? Is it because I use @Scope ("request")?

If this helps the Jetty 7.1.4 servlet container, and I use the standard WAR for deployment.

+3
source share
1 answer

, ! System.out.println( " !" )

, - @Scope ( "" ) @Scope ( "singleton" ) "bean" .

0

Source: https://habr.com/ru/post/1776548/


All Articles