my.war/META-INF/MANIFEST.MF:
Class-Path:
ibatis-common-2.jar ibatis-dao-2.jar ibatis-sqlmap-2.jar
my.war/WEB-INF/spring-context.xml:
<bean id="dataSource"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName"
value="java:/DataSource"/>
</bean>
<bean id="sqlMapClient"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"
singleton="true">
<property name="configLocation"
value="classpath:SQLMapConfig.xml"/>
<property name="dataSource"
ref="dataSource"/>
<!-- I know, I'm not using Spring's
transaction management...I wasn't quite sure how to, but this ibatis class
gave me all the transaction support I needed -->
<property
name="transactionConfigClass"
value="com.ibatis.sqlmap.engine.transaction.jdbc.JdbcTransactionConfig"/>
</bean>
<bean id="myPersonDAO"
class="com.mycompany.myapp.dao.PersonDAO" signleton="true">
<property name="sqlMapClient"
ref="sqlMapClient"/>
</bean>
my.war/WEB-INF/web.xml:
<context-param>
<param-name>contextConfiguration</param-name>
<param-value>/WEB-INF/spring-context.xml</param-name>
</context-param>
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
Now, to get to a DAO, I just do this more or
less (actually, I never retrieve the DAOs directly, they're injected by
Spring into my Manager classes). These are all Spring classes, except
for the DAO:
ConfigurableWebApplicationContext context =
(ConfigurableWebApplicationContext)WebApplicationContextUtils.getRequiredWebApplicationContext(session.getServletContext());
ConfigurableBeanFactory factory =
(ConfigurableBeanFactory)context.getBeanFactory();
PersonDAO dao =
(PersonDAO)factory.getBean("myPersonDAO");
Everything's working fine, including
transactions, although I am curious how I could set it up to use the
external transaction config and Spring's transaction stuff. Hope this
helps.