|
I'm using iBATIS within a JBoss EAR. I'm
using Spring, though, which helps a lot. Anyways, here's how everything's
set up:
my.ear:
* my-daos.jar - contains my DAOs, all of
which extend
org.springframework.orm.ibatis.SqlMapClientDaoSupport
* my.war - contains Spring XML config
* ibatis-common-2.jar
* ibatis-dao-2.jar
* ibatis-sqlmap-2.jar
my.ear/META-INF/MANIFEST.MF:
Class-Path: ibatis-common-2.jar ibatis-dao-2.jar
ibatis-sqlmap-2.jar
my-daos.jar: contains all my sqlmaps underneath an
sqlmaps subdirectory and my DAOS
* sqlmaps/____SQLMap.xml
* com/mycompany/myapp/dao/___DAO.class
* SQLMapConfig.xml - the master configuration for
iBATIS
my.war:
* WEB-INF/spring-context.xml
* WEB-INF/web.xml
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. -Joe
|
- Re: iBatis within EAR files Joe Wolf
- Re: iBatis within EAR files Alexander Sack
- Re: iBatis within EAR files Joe Wolf
