vka2b
Aug 1st, 2006, 03:18 PM
Hi,
I apologize if this is covered elsewhere, but I feel that I’ve done a pretty thorough job trying to read what was applicable in the documentation and existing posts in the forum. Any advice anybody can give me would be greatly appreciated.
Let me explain the context in which I am trying to use Spring and then describe the details of my problem. We currently have a web application that is tied to specific web servers (Weblogic and Websphere). In order to break this dependency, we are taking a few steps, one of which is converting our existing EJB classes to POJO.
With the elimination of the EJB framework from our code, we need to implement some other form of transaction management. This is where we were hoping for Spring to come in. For now, all we want to use it for is transaction management and nothing else (with the hopes that in future releases of our application, we can integrate more and more of the Spring framework).
In order to achieve this, I am testing out Spring transaction management with just a few classes/methods. I have set up an applicationContext.xml that defines the beans for these classes/methods as well as ties them to a transaction manager. In dataAccessContext.xml I have defined the data source and transaction manager beans. I have added these to my web.xml, and can see based on the debug messages that these are getting properly initialized when I initialize my web server. The trouble I am having is that when I throw an exception from one of the methods defined in applicationContext.xml, nothing happens (i.e. the transaction doesn’t rollback). I don’t even see anything in my log file that indicates that Spring is even aware that an exception was thrown.
I know that something has to be wrong with my dataAccessContext.xml. Even though I can see that it is getting read in properly, I can put in completely invalid arguments (i.e. an incorrect URL) but I don’t get any errors or warnings, so clearly it’s not being used. I know that I must be missing something, but I am at a loss as for what. There is some sort of disconnect between my dataAccessContext.xml and my code that is actually getting a connection from the database, executing SQL across that connection, etc.
I am posting my applicationContext.xml, dataAccessContext.xml, web.xml, and excerpts from my logfile. If anything jumps out at anybody or you need anymore information to help me diagnose this, please let me know. Thanks in advance.
applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="alertAssignmentTarget" class="com.mantas.platform.admin.alertassign.AlertAssignm entRuleEntity"/>
<bean id="alertScoreTarget" class="com.mantas.platform.admin.alertscoreeditor.AlertSc oreStrategyEntity"/>
<bean id="matchScoreTarget" class="com.mantas.platform.admin.alertscoreeditor.MatchSc oreEntity"/>
<bean id="thresholdTarget" class="com.mantas.platform.admin.thresholdeditor.Threshol dEntity"/>
<bean id="appControllerTarget" class="com.mantas.platform.control.AppController"/>
<bean id="txProxyTemplate" abstract="true" class="org.springframework.transaction.interceptor.Transa ctionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager"/>
<property name="transactionAttributes">
<props>
<prop key="create">PROPAGATION_REQUIRED,-java.lang.Exception</prop>
<prop key="findByPrimaryKey">PROPAGATION_REQUIRED,readOnly,-RemoteException</prop>
<prop key="store">PROPAGATION_REQUIRED,-RemoteException</prop>
<prop key="load">PROPAGATION_REQUIRED,readOnly,-RemoteException</prop>
<prop key="remove">PROPAGATION_REQUIRED,-RemoteException</prop>
</props>
</property>
</bean>
<bean id="appController" class="org.springframework.transaction.interceptor.Transa ctionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager"/>
<property name="target" ref="appControllerTarget"/>
<property name="transactionAttributes">
<props>
<prop key="execute">PROPAGATION_REQUIRED,-java.lang.Exception</prop>
<prop key="callJavaMethod">PROPAGATION_REQUIRED,-Exception</prop>
</props>
</property>
</bean>
<bean id="alertAssignment" parent="txProxyTemplate">
<property name="target" ref="alertAssignmentTarget"/>
</bean>
<bean id="alertScore" parent="txProxyTemplate">
<property name="target" ref="alertScoreTarget"/>
</bean>
<bean id="matchScore" parent="txProxyTemplate">
<property name="target" ref="matchScoreTarget"/>
</bean>
<bean id="threshold" parent="txProxyTemplate">
<property name="target" ref="thresholdTarget"/>
</bean>
</beans>
As you can see, I am using both an abstract transaction proxy bean that the other beans inherit from as well as a non-template one (the latter being added to test a "normal" case in the chance that I was doing something wrong in setting up the relationship between parent/child beans).
Here is my dataAccessContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerD ataSource" destroy-method="close">
<property name="driverClassName"><value>oracle.jdbc.driver.OracleDriver</value></property>
<property name="url"><value>jdbc:oracle:oci:@D5O9S10</value></property>
<property name="username"><value>KDD_WEB</value></property>
<property name="password"><value>KDD_WEB</value></property>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTran sactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
</beans>
Here is my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2.2.dtd">
<web-app id="WebApp_1046465055226">
<servlet id="Servlet_1046464107434">
<servlet-name>RequestServlet</servlet-name>
<servlet-class>com.mantas.platform.web.RequestServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>BaseInitServlet</servlet-name>
<display-name>BaseInitServlet</display-name>
<servlet-class>com.mantas.platform.servlet.BaseInitServlet</servlet-class>
<init-param>
<param-name>WebAppType</param-name>
<param-value>@APPSERVER_NAME@</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServl et</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dataAccessContext.xml,/WEB-INF/applicationContext.xml</param-value>
</context-param>
<servlet-mapping id="ServletMapping_1046465055267">
<servlet-name>RequestServlet</servlet-name>
<url-pattern>/app/request/*</url-pattern>
</servlet-mapping>
<session-config id="SessionConfig_1046465055267">
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list id="WelcomeFileList_1046465055277">
<welcome-file>./platform/workflow/web/content/index.jsp</welcome-file>
</welcome-file-list>
<taglib id="TagLibRef_1046465055277">
<taglib-uri>/WEB-INF/ui-taglib.tld</taglib-uri>
<taglib-location>/WEB-INF/ui-taglib.tld</taglib-location>
</taglib>
</web-app>
My logfiles are huge, so I am just posting a few snippets to show that the beans actually are getting read in and initialized:
2006-07-31 16:31:15,119 [Thread-6] DEBUG Found 2 <bean> elements in ServletContext resource [/WEB-INF/dataAccessContext-local.xml]
2006-07-31 16:31:15,333 [Thread-6] DEBUG Loaded 11 bean definitions from location pattern [/WEB-INF/applicationContext.xml]
2006-07-31 16:31:15,334 [Thread-6] INFO Bean factory for application context [Root WebApplicationContext]: org.springframework.beans.factory.support.DefaultL istableBeanFactory defining beans [dataSource,transactionManager,alertAssignmentTar
get,alertScoreTarget,matchScoreTarget,thresholdTar get,appControllerTarget,txProxyTemplate,appControl ler,alertAssignment,alertScore,matchScore,threshol d]; root of BeanFactory hierarchy
As you can see, the beans are being loaded. However, that's where the success stops! Let's say, for example, that AlertAssignmentRuleEntity.create() inserts a record into the database and then throws an Exception. Based on my understanding of my configuration, the insert should get rolled back. However, this does not happen, and I do not see anything that tells me that Spring is even aware of this Exception being thrown.
If it helps diagnose the problem at all, here is something that has been confusing me: Our existing database code doesn't obtain a connection through a DataSource, it uses the DriverManager (this is why I thought DriverManagerDataSource was the right one to use). As such, I'm not entirely sure how to map it to a DataSource. This is also where I am unclear as to how Spring is aware of the database connection being used in the code (i.e. where exactly is the mapping between Spring and the connection obtained through the code)? I'm not sure if I articulated that question properly, but I guess I'll find out soon...
Again, my plea for help, and I'll close with that! Thanks.
I apologize if this is covered elsewhere, but I feel that I’ve done a pretty thorough job trying to read what was applicable in the documentation and existing posts in the forum. Any advice anybody can give me would be greatly appreciated.
Let me explain the context in which I am trying to use Spring and then describe the details of my problem. We currently have a web application that is tied to specific web servers (Weblogic and Websphere). In order to break this dependency, we are taking a few steps, one of which is converting our existing EJB classes to POJO.
With the elimination of the EJB framework from our code, we need to implement some other form of transaction management. This is where we were hoping for Spring to come in. For now, all we want to use it for is transaction management and nothing else (with the hopes that in future releases of our application, we can integrate more and more of the Spring framework).
In order to achieve this, I am testing out Spring transaction management with just a few classes/methods. I have set up an applicationContext.xml that defines the beans for these classes/methods as well as ties them to a transaction manager. In dataAccessContext.xml I have defined the data source and transaction manager beans. I have added these to my web.xml, and can see based on the debug messages that these are getting properly initialized when I initialize my web server. The trouble I am having is that when I throw an exception from one of the methods defined in applicationContext.xml, nothing happens (i.e. the transaction doesn’t rollback). I don’t even see anything in my log file that indicates that Spring is even aware that an exception was thrown.
I know that something has to be wrong with my dataAccessContext.xml. Even though I can see that it is getting read in properly, I can put in completely invalid arguments (i.e. an incorrect URL) but I don’t get any errors or warnings, so clearly it’s not being used. I know that I must be missing something, but I am at a loss as for what. There is some sort of disconnect between my dataAccessContext.xml and my code that is actually getting a connection from the database, executing SQL across that connection, etc.
I am posting my applicationContext.xml, dataAccessContext.xml, web.xml, and excerpts from my logfile. If anything jumps out at anybody or you need anymore information to help me diagnose this, please let me know. Thanks in advance.
applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="alertAssignmentTarget" class="com.mantas.platform.admin.alertassign.AlertAssignm entRuleEntity"/>
<bean id="alertScoreTarget" class="com.mantas.platform.admin.alertscoreeditor.AlertSc oreStrategyEntity"/>
<bean id="matchScoreTarget" class="com.mantas.platform.admin.alertscoreeditor.MatchSc oreEntity"/>
<bean id="thresholdTarget" class="com.mantas.platform.admin.thresholdeditor.Threshol dEntity"/>
<bean id="appControllerTarget" class="com.mantas.platform.control.AppController"/>
<bean id="txProxyTemplate" abstract="true" class="org.springframework.transaction.interceptor.Transa ctionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager"/>
<property name="transactionAttributes">
<props>
<prop key="create">PROPAGATION_REQUIRED,-java.lang.Exception</prop>
<prop key="findByPrimaryKey">PROPAGATION_REQUIRED,readOnly,-RemoteException</prop>
<prop key="store">PROPAGATION_REQUIRED,-RemoteException</prop>
<prop key="load">PROPAGATION_REQUIRED,readOnly,-RemoteException</prop>
<prop key="remove">PROPAGATION_REQUIRED,-RemoteException</prop>
</props>
</property>
</bean>
<bean id="appController" class="org.springframework.transaction.interceptor.Transa ctionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager"/>
<property name="target" ref="appControllerTarget"/>
<property name="transactionAttributes">
<props>
<prop key="execute">PROPAGATION_REQUIRED,-java.lang.Exception</prop>
<prop key="callJavaMethod">PROPAGATION_REQUIRED,-Exception</prop>
</props>
</property>
</bean>
<bean id="alertAssignment" parent="txProxyTemplate">
<property name="target" ref="alertAssignmentTarget"/>
</bean>
<bean id="alertScore" parent="txProxyTemplate">
<property name="target" ref="alertScoreTarget"/>
</bean>
<bean id="matchScore" parent="txProxyTemplate">
<property name="target" ref="matchScoreTarget"/>
</bean>
<bean id="threshold" parent="txProxyTemplate">
<property name="target" ref="thresholdTarget"/>
</bean>
</beans>
As you can see, I am using both an abstract transaction proxy bean that the other beans inherit from as well as a non-template one (the latter being added to test a "normal" case in the chance that I was doing something wrong in setting up the relationship between parent/child beans).
Here is my dataAccessContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerD ataSource" destroy-method="close">
<property name="driverClassName"><value>oracle.jdbc.driver.OracleDriver</value></property>
<property name="url"><value>jdbc:oracle:oci:@D5O9S10</value></property>
<property name="username"><value>KDD_WEB</value></property>
<property name="password"><value>KDD_WEB</value></property>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTran sactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
</beans>
Here is my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2.2.dtd">
<web-app id="WebApp_1046465055226">
<servlet id="Servlet_1046464107434">
<servlet-name>RequestServlet</servlet-name>
<servlet-class>com.mantas.platform.web.RequestServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>BaseInitServlet</servlet-name>
<display-name>BaseInitServlet</display-name>
<servlet-class>com.mantas.platform.servlet.BaseInitServlet</servlet-class>
<init-param>
<param-name>WebAppType</param-name>
<param-value>@APPSERVER_NAME@</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServl et</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dataAccessContext.xml,/WEB-INF/applicationContext.xml</param-value>
</context-param>
<servlet-mapping id="ServletMapping_1046465055267">
<servlet-name>RequestServlet</servlet-name>
<url-pattern>/app/request/*</url-pattern>
</servlet-mapping>
<session-config id="SessionConfig_1046465055267">
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list id="WelcomeFileList_1046465055277">
<welcome-file>./platform/workflow/web/content/index.jsp</welcome-file>
</welcome-file-list>
<taglib id="TagLibRef_1046465055277">
<taglib-uri>/WEB-INF/ui-taglib.tld</taglib-uri>
<taglib-location>/WEB-INF/ui-taglib.tld</taglib-location>
</taglib>
</web-app>
My logfiles are huge, so I am just posting a few snippets to show that the beans actually are getting read in and initialized:
2006-07-31 16:31:15,119 [Thread-6] DEBUG Found 2 <bean> elements in ServletContext resource [/WEB-INF/dataAccessContext-local.xml]
2006-07-31 16:31:15,333 [Thread-6] DEBUG Loaded 11 bean definitions from location pattern [/WEB-INF/applicationContext.xml]
2006-07-31 16:31:15,334 [Thread-6] INFO Bean factory for application context [Root WebApplicationContext]: org.springframework.beans.factory.support.DefaultL istableBeanFactory defining beans [dataSource,transactionManager,alertAssignmentTar
get,alertScoreTarget,matchScoreTarget,thresholdTar get,appControllerTarget,txProxyTemplate,appControl ler,alertAssignment,alertScore,matchScore,threshol d]; root of BeanFactory hierarchy
As you can see, the beans are being loaded. However, that's where the success stops! Let's say, for example, that AlertAssignmentRuleEntity.create() inserts a record into the database and then throws an Exception. Based on my understanding of my configuration, the insert should get rolled back. However, this does not happen, and I do not see anything that tells me that Spring is even aware of this Exception being thrown.
If it helps diagnose the problem at all, here is something that has been confusing me: Our existing database code doesn't obtain a connection through a DataSource, it uses the DriverManager (this is why I thought DriverManagerDataSource was the right one to use). As such, I'm not entirely sure how to map it to a DataSource. This is also where I am unclear as to how Spring is aware of the database connection being used in the code (i.e. where exactly is the mapping between Spring and the connection obtained through the code)? I'm not sure if I articulated that question properly, but I guess I'll find out soon...
Again, my plea for help, and I'll close with that! Thanks.