开发者

@PostConstruct method called all the time on Jersey service

Hi I'm using GigaSpaces XAP which basically uses Spring and ApplicationContext to do all it's 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 instantiated and is made available through the ServletContext. This space proxy is what allows you to write and read to and from the clustered cache.

So what I did initially was to get the space on each REST method. So...

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

Since t开发者_如何学运维he space itself is thread safe I was instructed by the GigaSpaces guys to lookup the space once on init of my "application" so i can save on the lookup of the space.

So I looked into @PostConstruct where I did...

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

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

If it Helps the servlet container is Jetty 7.1.4 and I'm using standard WAR to deploy.


But of course! System.out.println("Is your friend!")

And yes it is because of @Scope("request") changing to @Scope("singleton") causes the jersey "bean" to instantiate once instead of per request.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜