ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Joe Wolf" <joe.w...@compsciresources.com>
Subject Re: iBatis within EAR files
Date Tue, 11 Apr 2006 23:03:17 GMT
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
  ----- Original Message ----- 
  From:  
  To: user-java@ibatis.apache.org 
  Sent: Friday, April 07, 2006 5:44 PM
  Subject: Re: iBatis within EAR files


  Hi Hans,

  I did this:

  my.ear:
  my.jar
  lib/my-ibatis-lib.jar
  lib/ibatis-common-2.jar
  lib/ibatis-sqlmap-2.jar
  lib/ibatis-dao-2.jar

  my.jar/MANIFEST.MF
  Class-Path: lib/my-ibatis-lib.jar lib/ibatis-common-2.jar etc.

  my-ibatis-lib.jar
  blah/blah/blah/sqlMapConfig.xml

  From within EJB3 my.jar, I'm doing getResourceAsReader("blah/blah/blah/sqlMapConfig.xml")
and I still get IOException, it can't find it.  OMG...I'm gong to pull out all of my hair
and I'm already bald!.  If iBatis is added to the system classloader due to the MANIFEST entry
then I maybe screwed no matter what.  My only last resort is to see if java2Parent delegation
will have an effect on this.

  This is such a basic configuration and I cna't believe I'm the only one who has ran into
this.  Has anyone used iBatis from an EAR under JBoss?  If so, can you please just give me
your package layout?

  -aps


  On 4/7/06, Beemsterboer Software <hans@beemsterboer-software.nl> wrote:
    Alexander,

    When I understand it correctly, you have the iBatis jar files in the EAR
    project and
    the iBatis configuration in the EJB project.

    Can you try to extract these configuration files and add them as a 
    'shared library' to your application?
    This is a 'good practice':
    - You can configure your application without changing the EAR file.

    Also, it may solve your classloading problem.

    Greetings,
    Hans. 






  -- 
  "What lies behind us and what lies in front of us is of little concern to what lies within
us." -Ralph Waldo Emerson 
Mime
View raw message