When customizing an EMC Documentum WebTop application and using the Spring Framework to tie everything together, you find yourself wishing you could use Dependency Injection at all places in the existing WebTop source.
I don’t yet know of a workable way to achive that sort of plumbing with a WebTop application (especially for all types of existing components and tags) to just expose any new dependencies and let Spring handle it all.
Another way to achive interoperability with Spring and still use most of what’s good there is to allow our legacy components to have access to a Spring ApplicationContext, but setting one using Spring is not feasible because of the same reasons as above. Thus we introduce the StaticSpringApplicationContext.
The StaticSpringApplicationContext works simply by containing a static reference to the Spring ApplicationContext and exposing a static helper method to get beans configured by Spring.
Configure the helper class by defining it in your web.xml like so:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
And at least the following in your WEB-INF/applicationContext.xml file:
<bean id="StaticSpringApplicationContext"
class="com.palbrattberg.spring.StaticSpringApplicationContext" />
This will make sure Spring itself configures the StaticSpringApplicationContext on startup.
Now you can simply get your configured beans (preferably in your constructor) like this:
MyBean myBean = (MyBean) StaticSpringApplicationContext.getBean("myBean");
Now you are free to use Spring for configuring all your future code.
Source code for StaticSpringApplicationContext
Recent Comments