Spring @Autowired and WebApplicationContext in Tomcat

Posted by EugeneP on Stack Overflow See other posts from Stack Overflow or by EugeneP
Published on 2010-05-07T14:44:07Z Indexed on 2010/05/07 14:48 UTC
Read the original article Hit count: 377

Filed under:
|
|
|

@Autowired works only once.

What to do to make it wire the bean every time the Servlet is recreated?

My web-app (Tomcat6 container) consists of 2 Servlets. Every servlet has private fields.

Their setters are marked with @Autowired

In the init method I use

WebApplicationContextUtils
...
autowireBean(this);

It autowires the properties marked with @Autowired once - during the initialization of the Servlet.

Any other session will see these fields values, they will not be rewired after the previous session is destroyed.

What to do to make them rewire them each time a Servlet constructor is called?

a) Put the autowiring into the constructor?

Or better 2) get a web app context and extract a bean from there?

© Stack Overflow or respective owner

Related posts about java

Related posts about spring