
Originally Posted by
scottyfred
Taran,
Thanks for your prompt reply !
When splitting the application contexts like this, the two contexts have a parent-child relationship. The context passed to the contextLoaderListener becomes the parent of the DispatcherServlet's context. So, all beans declared in applicationContext.xml should also be visible to the DispatcherServlet's context.
That must contain the answer, but I'm not sure if I need to do some extra configuration for this parent-child (applcation-context --> web-application-context). I'm under the impression that this happens by default in Spring MVC. Is that correct?
You say that the tx manager works in one case but doesn't work in another case. What exactly happens when the tx manager doesn't work? Are you getting an error when the app context tries to load, or is the app just not behaving as you expect it to?
Yes if I remove the application-context file entry from Dispatcher servlet as highlighted in red below, then the transaction don't get started.
Please note, I'm using annotation based transaction management defined in applicationContext.xml and I'm using container managed transaction manager from JBoss (JTA)
Web.xml
Code:
<servlet>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/config/servlet-context.xml /WEB-INF/config/applicationContext.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
Transaction Manager config
Code:
<jee:jndi-lookup id="dataSource" jndi-name="java:OracleDS"/>
Annotation snippet
Code:
@Transactional(
propagation = Propagation.REQUIRED,
isolation = Isolation.DEFAULT,
readOnly = false)
public interface LoginService {
public LoginVO getUserDetails(String userID);
}
<tx:annotation-driven/>
<tx:jta-transaction-manager/>
Logs show that the JtaTransactionManager started, but when the transactional methods are called, no transaction gets bounded/started. I verified via setting logger level to DEBUG
Logs
HTML Code:
12:37:35,921 INFO [STDOUT] INFO : org.springframework.transaction.jta.JtaTransactionManager - Using JTA TransactionManager: com.arjuna.ats.jbossatx.jta.TransactionManagerDelegate@b4870
12:37:35,922 INFO [STDOUT] DEBUG: org.springframework.transaction.jta.JtaTransactionManager - JTA TransactionSynchronizationRegistry found at default JNDI location [java:comp/TransactionSynchronizationRegistry]
12:37:35,922 INFO [STDOUT] INFO : org.springframework.transaction.jta.JtaTransactionManager - Using JTA TransactionSynchronizationRegistry: com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple@c0bb57
[20