vendredi 24 juillet 2015

Here is my problem, I want to define 2 Maven profiles,

one for the dev environment and

one for the prod environment.

In my pom.xml, I so defined 2 profiles :

<!-- pom.xml -->

<profiles>

    .....

    <profile>
      <id>dev</id>
      <activation>
        <property>
          <name>environment</name>
          <value>dev</value>
        </property>
        <activeByDefault>true</activeByDefault>
      </activation>
    </profile>

    <profile>
      <id>prod</id>
      <activation>
        <property>
          <name>environment</name>
          <value>prod</value>
        </property>
      </activation>
    </profile>

</profiles>

and in my context.xml file, I want to use a different dataSource according to which profile I choosed :

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://ift.tt/GArMu6"
    xmlns:xsi="http://ift.tt/ra1lAU" xmlns:aop="http://ift.tt/OpNdV1"
    xmlns:context="http://ift.tt/GArMu7"
    xmlns:jee="http://ift.tt/OpNaZ5" xmlns:jd="http://ift.tt/18IIlo0"
    xmlns:p="http://ift.tt/1jdM0fE" xmlns:tx="http://ift.tt/OGfeU2"
    xmlns:sws="http://ift.tt/KZYGcT"
    xmlns:util="http://ift.tt/OGfeTW"
    xsi:schemaLocation="http://ift.tt/GArMu6 http://ift.tt/18sW2ax
        http://ift.tt/GArMu7 http://ift.tt/QEDs1k
        http://ift.tt/OpNaZ5 http://ift.tt/1j5lSTg
        http://ift.tt/OGfeU2 http://ift.tt/1cQrvTl
        http://ift.tt/18IIlo0 http://ift.tt/1CYUSmd
        http://ift.tt/OGfeTW http://ift.tt/1feTls0">

    <context:component-scan base-package="xxx.xxx.xxx.dao" />       

    <!-- DEV -->
    <bean p:profiles="dev" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource" >     
        <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
        <property name="url" value="jdbc:oracle:thin:@127.0.0.1:1522:******" />     
        <property name="username" value="******" />
        <property name="password" value="******" />
    </bean>     

    <!-- PROD -->
    <bean p:profiles="prod" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource">
        <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
        <property name="url" value="jdbc:oracle:thin:@xxxx.xxxx.xxxx.xxxx:1521:******" />
        <property name="username" value="******" />
        <property name="password" value="******" />
    </bean>

    <bean  id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
        </property>
        <property name="persistenceUnitName" value="carfleetPersistenceUnit" />
        <property name="dataSource" ref="dataSource" />
    </bean>

    <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

    <tx:annotation-driven />

</beans>    

I for sure did something wrong in the configuration or the utilisation of theses profiles... but I don't know what...

I'm building with maven by using the command :

mvn -e -Denvironment=dev clean package tomcat7:redeploy

But I got the error :

Configuration problem : Bean name "dataSource" is already used in this <beans> element.

If someone can tell me what is wrong :/ Because I test a lot of things, but it's just giving different errors, I don't know exactly what to do to fix it.

Thanks in advance !

Aucun commentaire:

Enregistrer un commentaire