Since Websphere takes care of the instantiation of the custom workflow action class as configured in plugin.xml you need a method for injecting your spring application context.
There are two ways that you can do this:
1) Configure a SingletonBeanFactoryLocator to load a single instance of your application context
-- I had classpath problems loading the beanRefFactory.xml off the classpath. Not sure why this was the case.
2) Use a standard spring web ContextLoaderListener. Define a single bean in myappcontext.xml (or more if desired) that is ApplicationContextAware, that accepts and sets applicationContext statically ...
web.xml:
1: <context-param>
2: <param-name>contextConfigLocation</param-name>
3: <param-value>/WEB-INF/spring/my-workflow-init-appcontext.xml</param-value>
4: </context-param>
5:
6: <listener>
7: <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
8: </listener>
1: /**
2: * Statically returns the loaded application context
3: * @author Shaun.Domingo
4: */
5: public class ApplicationContextProvider implements ApplicationContextAware {
6:
7: private static ApplicationContext applicationContext = null;
8:
9: public static ApplicationContext getApplicationContext() {
10: return applicationContext;
11: }
12:
13: public void setApplicationContext(ApplicationContext applicationContext)
14: throws BeansException {
15: this.applicationContext = applicationContext;
16: }
17: }
Then in your CustomWorkflowAction call ApplicationContextProvider (call it what you will) to retrieve the application context and grab an instance of your beans by name (or by Class if using Spring 3).
Seems to work well to date.
0 comments:
Post a Comment