Announcement Announcement Module
Collapse
No announcement yet.
Convert legacy code to Spring Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Convert legacy code to Spring

    Hi, I would like to convert our application to Spring. I would like to start with my DAO objects. At the present moment I do not want to rewrite any DAO's to use the JdbcDaoSupport or JdbcTemplate. I would really like to use my existing DAO's with declaritive transaction management. Here are the things I think I need to do. Please correct me if I am incorrect or have missed something.

    1. Inject DAO's with Spring managed datasource.
    2. Obtain and close database connection via DatasourceUtils methods.
    3. Configure datasource to use DataSourceTransactionManager.
    4. Configure business object to use TransactionProxyFactoryBean.

    Regards

  • #2
    Item 3 is actually the other way around - the DataSourceTransactionManager is configured with a reference to the DataSource - the DataSource is unaware of the DataSourceTransactionManager. That's why you need the DataSourceUtils to manage the connections.

    An alternative for legacy code is to use TransactionAwareDataSourceProxy to wrap the DataSource. This eliminates the need to modify the legacy code to use DataSourceUtils - you can just let the legacy code issue a getConnection on the DataSource which now is wrapped by this proxy.

    Comment


    • #3
      Convert legacy code to Spring

      Would it be possible to please provide an example of how to configure
      TransactionAwareDataSourceProxy in my applicationContext.xml?
      I know it may be trivial but I would reallly appreciate any help.


      Regards

      Comment


      • #4
        Try the following -
        Code:
        <bean id="dataSource" class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy">
        	<property name="targetDataSource">
        		<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        			<property name="driverClassName"><value>$&#123;jdbc.driverClassName&#125;</value></property>
        			<property name="url"><value>$&#123;jdbc.url&#125;</value></property>
        			<property name="username"><value>$&#123;jdbc.username&#125;</value></property>
        			<property name="password"><value>$&#123;jdbc.password&#125;</value></property>
        		</bean>
        	</property>
        </bean>

        Comment

        Working...
        X