How can I define one ApplicationContext as a spring bean prototype in a different application context. I also need to pass the current context as a parent to the new application context.
More details:
I have Bean, which are one user sessions in a rich client application. This class controls the lifetime of the application context and several other objects (for example, connecting to the database). This beans session itself is configured with a special "launch application context".
Now I want to unit test this beans session, but you have problems because the session-specific application context created inside the Bean session depends a lot on the “launch context”;
Code example:
public class UserDBAminSession implements ApplicationContextAware, UserSession {
ApplicationContext startupContext;
ApplicationContext sessionContext;
public void setApplicationContext(ApplicationContext startupContext) {...}
public void start() {
createSessionContext() ;
}
private void createSessionContext() {
sessionContext = new ClassPathXmlApplicationContext("admin-session.xml", startupContext);
}
}
, createSessionContext - :
sessionContext = startupContext.getBean("adminContext", ApplicationContext.class);
mock startupContext, . DI " " bean spring, . , ClassPamlApplicationContext. - , , :
<bean id="adminContext" class="org.springframework.context.support.ClassPathXmlApplicationContext"
scope="prototype" autowire="constructor">
<constructor-arg type="java.lang.String">
<value>admin-session.xml</value>
</constructor-arg>
</bean>
setter, :
- , . (UserSession - " " ).
- RAII.
- .
" factory", .
, IoC IoC. , spring?
, unit-test ?