Announcement Announcement Module
Collapse
No announcement yet.
Define DAO-Implementation with Maven-Profile Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Define DAO-Implementation with Maven-Profile

    Hello folks,

    i have a strange idea ...
    i would like define the used dao-implementation in a maven-profile ...
    a example:

    spring-dao.xml:

    Code:
      <bean id="remoteDao" class="de.ahoehma.dao.Remote" scope="session">
        <aop:scoped-proxy />
        <property name="profile"value="${dao_profile}" />
      </bean>
      
      <bean id="localDao" class="de.ahoehma.dao.Local" scope="session">
        <aop:scoped-proxy />
        <property name="profile" value="${dao_profile}"/>
        <property name="license" value="/db/123456.TXT"/>
      </bean>
    spring-services.xml:

    Code:
      <bean id="FoobarService" class="de.ahoehma.service.FoobarService">
        <property name="dao" ref="${daoImpl}"/>
      </bean>
    imagine there are more dao-implementations possible ... so i would *not* include every possible dao-impl into my dao.xml.
    so how can i define "dynamic" the real bean for "${daoImpl}"?

    I want create the war-file (i have a j2ee app) with a simple maven-call:

    mvn package -Pdao-local
    or
    mvn package -Pdao-remote
    or
    mvn package -Pdao-whatever

    in the maven-profiles i would define the dao which should be used:

    Code:
    <profile>
      <id>dao-local</id>
      <properties>
         <dao-impl>localDao</dao-impl>
      </properties>
    </profile>
    <profile>
      <id>dao-remote</id>
      <properties>
         <dao-impl>remoteDao</dao-impl>
      </properties>
    </profile>
    then maven can filter my propertie-files, e.g. a dao.properties:

    Code:
    daoImpl=${dao-impl}
    so a spring PropertyPlaceholderConfigurer can read the property "daoImpl".
    but here is the problem "i can use a placeholder for a bean-ref" :-(

    ref="${daoImpl}" is not possible

    any ideas?
    regards
    andreas
    Last edited by ahoehma; Aug 29th, 2008, 03:27 AM.

  • #2
    a dynamic import will not work:

    spring-dao-remote.xml

    Code:
      <bean id="Dao" class="de.ahoehma.dao.Remote" scope="session">
        <aop:scoped-proxy />
        <property name="profile"value="${dao_profile}" />
      </bean>
    spring-dao-local.xml

    Code:
      
      <bean id="Dao" class="de.ahoehma.dao.Local" scope="session">
        <aop:scoped-proxy />
        <property name="profile" value="${dao_profile}"/>
        <property name="license" value="/db/123456.TXT"/>
      </bean>
    spring-services.xml

    Code:
      <import resource="classpath:${dao-config}"/>
    
      <bean id="FoobarService" class="de.ahoehma.service.FoobarService">
        <property name="dao" ref="Dao"/>
      </bean>
    with dao.properties

    Code:
    dao-config=spring-dao-remote.xml
    or

    Code:
    dao-config=spring-dao-local.xml

    Comment


    • #3
      i found a way ... but not the best solution ...

      spring-dao-remote.xml

      Code:
        <bean id="DaoRemote" class="de.ahoehma.dao.Remote" scope="session">
          <aop:scoped-proxy />
          <property name="profile"value="${dao_profile}" />
        </bean>
      spring-dao-local.xml

      Code:
        
        <bean id="DaoLocal" class="de.ahoehma.dao.Local" scope="session">
          <aop:scoped-proxy />
          <property name="profile" value="${dao_profile}"/>
          <property name="license" value="/db/123456.TXT"/>
        </bean>
      spring-services.xml

      Code:
        <import resource="spring-dao-local.xml"/>
        <import resource="spring-dao-remote.xml"/>
      
        <bean id="FoobarService" class="de.ahoehma.service.FoobarService">
          <property name="dao">
            <ref bean="${daoImpl}"/>
          </property>
        </bean>
      with

      Code:
      daoImpl=DaoLocal
      or

      Code:
      daoImpl=DaoRemote
      It works but i have to include all possible spring-dao-XXX.xml :-(

      Comment


      • #4
        We have a project called JavaConfig which might be what you want to use. Joris and Alef gave a presentation about this on how to switch between environments.

        Comment


        • #5
          Found something

          http://blog.arendsen.net/index.php/2...t-with-spring/

          Works for me ... but with the lack of importing all known dao-configurations,
          a dynamic import would be nice

          Comment


          • #6
            Originally posted by Marten Deinum View Post
            We have a project called JavaConfig which might be what you want to use. Joris and Alef gave a presentation about this on how to switch between environments.
            Hi Marten, please post a URL. thxs

            Comment

            Working...
            X