Announcement Announcement Module
Collapse
No announcement yet.
Different datas source for CI server and IDE Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Different datas source for CI server and IDE

    Hi everyone

    I wasn't able to solve my problem with any hints I found in the internet, please tell me if this questions has already been answered somewhere else.

    Now the question: I would like to specify different database URL, user name and password for the CI server and the IDE. I put the database.properties file on Subversion and created a second one, database.personal.properites, to store my local settings. How can I tell Spring Roo to use database.personal.properties if available and database.properties otherwise?

    Here is what I've modified already:

    Excerpt from applicationContext.xml:
    Code:
        <bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSourceCI">
            <property name="driverClassName" value="${database.driverClassName}"/>
            <property name="url" value="${database.url}"/>
            <property name="username" value="${database.username}"/>
            <property name="password" value="${database.password}"/>
            <property name="testOnBorrow" value="true"/>
            <property name="testOnReturn" value="true"/>
            <property name="testWhileIdle" value="true"/>
            <property name="timeBetweenEvictionRunsMillis" value="1800000"/>
            <property name="numTestsPerEvictionRun" value="3"/>
            <property name="minEvictableIdleTimeMillis" value="1800000"/>
            <property name="validationQuery" value="SELECT 1"/>
        </bean>
        <bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSourcePersonal">
            <property name="driverClassName" value="${database.driverClassName}"/>
            <property name="url" value="${database.personal.url}"/>
            <property name="username" value="${database.personal.username}"/>
            <property name="password" value="${database.personal.password}"/>
            <property name="testOnBorrow" value="true"/>
            <property name="testOnReturn" value="true"/>
            <property name="testWhileIdle" value="true"/>
            <property name="timeBetweenEvictionRunsMillis" value="1800000"/>
            <property name="numTestsPerEvictionRun" value="3"/>
            <property name="minEvictableIdleTimeMillis" value="1800000"/>
            <property name="validationQuery" value="SELECT 1"/>
        </bean>
        <bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManagerCI">
            <property name="entityManagerFactory" ref="entityManagerFactoryCI"/>
        </bean>
        <bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManagerPersonal">
            <property name="entityManagerFactory" ref="entityManagerFactoryPersonal"/>
        </bean>
        <tx:annotation-driven mode="aspectj" transaction-manager="transactionManagerCI"/>
        <tx:annotation-driven mode="aspectj" transaction-manager="transactionManagerPersonal"/>
        <bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactoryCI">
            <property name="persistenceUnitName" value="persistenceUnit"/>
            <property name="dataSource" ref="dataSourceCI"/>
        </bean>
        <bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactoryPersonal">
            <property name="persistenceUnitName" value="persistenceUnit"/>
            <property name="dataSource" ref="dataSourcePersonal"/>
        </bean>
    I should add that the application skeleton was working before on the CI server.

    Thanks for your help!

    Paul

  • #2
    I have found a way, not the most elegant one but it will do at the moment:

    applicationContext.xml:
    Code:
    <context:property-placeholder location="classpath*:META-INF/spring/**/database.properties"/>
    <context:property-override ignore-unresolvable="true" location="classpath*:META-INF/spring/**/database.personal.properties"/>
    I reverted all other changes to applicationContext.xml changed the properties of database.personal.properties to the dataSource bean:
    Code:
    dataSource.driverClassName=com.mysql.jdbc.Driver
    dataSource.url=jdbc\:mysql\://127.0.0.1\:3306/database
    dataSource.username=root
    dataSource.password=root
    It's not the most elegant solution because it replaces the values of the dataSource bean properties to the ones defined in database.personal.properties.

    Example:
    Code:
    <property name="driverClassName" value="${database.driverClassName}"/>
    becomes
    Code:
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    I looked for a way that overrides the runtime value of ${database.driverClassName} to the value specified in database.personal.properties.

    I hope this is of help for other newbies as well. I'm still interested in a more elegant solution.

    Comment


    • #3
      I've found the best solution so far.

      applicationContext.xml:
      Code:
      <context:property-placeholder location="classpath*:META-INF/spring/**/*.properties, file:*.personal.properties" ignore-resource-not-found="true" />
      The files found at the file path have a higher precedence and are referenced from the deployment path (Tomcat, JBoss,).

      Comment


      • #4
        Spring 3.1 comes up with a feature called as profiles. Please go through the below link and see if this is of any help to your problem

        http://blog.springsource.org/2011/02...ucing-profile/

        Comment

        Working...
        X