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 Wed, 12 Apr 2006 16:38:30 GMT
Unfortunately, I haven't tried it without Spring.  I forgot to mention that the Spring jar
was also directly underneath my ear and included in the Class-Path of both my ear file's and
war file's manifests.  It looks like Spring gets the SQLMap with the ContextClassLoader, too.

-Joe


  ----- Original Message ----- 
  From: Alexander Sack 
  To: user-java@ibatis.apache.org 
  Sent: Wednesday, April 12, 2006 12:16 AM
  Subject: Re: iBatis within EAR files


  Hey Joe, thanks a lot for the response!

  To be honest, I have another group within the project who also uses Spring in this exact
manner to get iBatis working within a JBoss EAR.  However, I'm trying to avoid the use of
yet another IoC technology in my project unless I really really have too.  Currently I have
everything working by playing with the context classloader at sqlMap load time which does
the trick.

  If I had time, I would probably convert the DAO facade layer to something that use the Persistence
API which is annotation based (and less side XML files which I don't like in general).

  All I can say is that the UCL3 in JBoss is very strange in regards to EAR scope and optional
libraries via the Class-Path manifest entries (like I said, I filed a bug report on it since
I really believe its not right.

  I'm assuming you haven't tried it without Spring?

  -aps


  On 4/11/06, Joe Wolf <joe.wolf@compsciresources.com> wrote:
    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 



  -- 
  "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