Setting a global variable in Struts with Spring
What is the best approach for setting a servlet context variable in Struts? This variable is displayed on every separate header page and must be loaded from the DB. There is Hibernate DAO and Spring Service for this, which returns the requested value.
My current approach was to extend the Plugins PlugIn class and inject my service into it. This cannot be done directly in Struts, but I found a page ( http://opensource.atlassian.com/confluence/spring/display/DISC/Spring-enabling+Struts+PlugIns ) where Ulrik Sandberg creates a proxy that allows this Functionality. This works when I deploy my app, but JUnits don't work somewhere in servletunit.struts.MockStrutsTestCase.getActionServlet (MockStrutsTestCase.java:331) on java.lang.NullPointerException.
Is there any other approach I can take that doesn't involve debugging other classes?
Have a look at the spring reference manual and section (3.4) on bean scope. You can have a bean that has been maintained throughout the entire browser session and set it up as a proxy session bean.
<!-- a HTTP Session-scoped bean exposed as a proxy -->
<bean id="userPreferences" class="com.foo.UserPreferences" scope="session">
<!-- this next element effects the proxying of the surrounding bean -->
<aop:scoped-proxy />
</bean>
This is from section 3.4.4.5.
a source to share