In setSessionContext you would set:
Code:
setBeanFactoryLocator(ContextSingletonBeanFactoryLocator.getInstance());
setBeanFactoryLocatorKey("Type1.context");
So your EJB would use a shared context. If you wanted two shared contexts, you'd need to create two different contexts identified by two different beanFactoryLocatorKey (Type1.context, Type2.context). They could share the same application context files. In fact they could share any XML files they wanted, and could differ however you wanted.
Since you want to change the isolation levels between the beans you'd need some different XML files as well as shared:
Type1.xml:
Code:
<bean id="sharedTransactionAttributes" class="java.util.Properties>
<constructor-arg>
<props>
<!-- transaction attributes go here -->
</props>
</constructor-arg>
</bean>
Type2.xml:
Code:
<bean id="sharedTransactionAttributes" class="java.util.Properties>
<constructor-arg>
<props>
<!-- transaction attributes go here -->
</props>
</constructor-arg>
</bean>
SharedComponents.xml
Code:
<bean id="blah" class="TransactionProxyFactoryBean">
<property name="transactionAttributes ref="sharedTransactionAttributes"/>
<!-- other stuff goes here -->
</bean>
beanRefContext.xml:
Code:
<bean id="Type1.context" class="org.springframework.context.support.ClassPathXmlApplicationContext">
<constructor-arg value="Type1.xml,SharedComponents.xml"/>
</bean>
<bean id="Type2.context" class="org.springframework.context.support.ClassPathXmlApplicationContext">
<constructor-arg value="Type2.xml,SharedComponents.xml"/>
</bean>
Note that the name of the beans is the name of the beanFactoryLocatorKey.
Your system will have two copies of the shared components, one tailored to your Type1 scenario and another for the Type2 scenario.
Although there isn't any reason to use a ContextSingletonBeanFactoryLocator, since that only refers to what kind of class is used to process the beanRefContext.xml. A SingletonBeanFactoryLocator would work just as well. Just change the name of beanRefContext.xml to beanRefFactory.xml. See the javadoc for these two classes to get more information about them.