Using spring cloud namespace and two DataSources -


i have spring integration war component i'm updating run in private pcf. have 2 datasources , rabbitmq connection factory defined in application.

i see article thomas risberg on using cloud namespace , handling multiple services of same time - https://spring.io/blog/2011/11/09/using-cloud-foundry-services-with-spring-part-3-the-cloud-namespace. handled using @autowired , @qualifier annotations.

i'm wondering how can achieved though when we're not @autowired , @qualifier annotations, e.g. wiring datasource jdbctemplate. here not have ability specify @qualifier annotation.

my application spring xml config based. have ability use @autowired , @qualifier annotations on 1 of datasources, other jpa entity manager. see code snippet.

any appreciated.

    <bean id="entitymanagerfactory"         class="org.springframework.orm.jpa.localcontainerentitymanagerfactorybean">         <property name="datasource" ref="datasource" />         <property name="persistenceunitname" value="activity-monitor" />         <property name="jpavendoradapter" ref="jpavendoradapter"/>         <property name="jpaproperties">             <value>                 hibernate.format_sql=true             </value>         </property>     </bean>      <beans profile="cloud">         <cloud:data-source id="datasource" service-name="actmon-db-service" />     </beans> 

java build pack: java_buildpack_offline java-buildpack-offline-v2.4.zip spring auto-reconfiguration version 1.4.0.

update: full config both data sources, including propertysourcesplaceholderconfigurer properties loaded data source using dao.

<bean id="cic.application.ppc" class="org.springframework.context.support.propertysourcesplaceholderconfigurer">      <property name="properties" ref="cic.application.properties"/>      <property name="locations" ref="cic.application.propertylocations"/>  </bean>  <bean id="cic.application.properties" class="java.util.properties">     <constructor-arg value="#{cicpropertiesservice.properties}"></constructor-arg> </bean>  <bean id="cic.properties.propertiesservice" name="cicpropertiesservice"     class="com.emc.it.eis.properties.service.defaultpropertiesservice">     <constructor-arg index="0"         ref="cic.properties.propertiesdao" /> </bean>  <bean id="cic.properties.propertiesdao" class="com.emc.it.eis.properties.dao.jdbcpropertiesdao">     <constructor-arg ref="cic.properties.datasource" /> </bean>  <beans profile="default">     <jee:jndi-lookup id="cic.properties.datasource"         jndi-name="jdbc/intdb" /> </beans>  <beans profile="cloud">     <cloud:data-source id="cic.properties.datasource" service-name="oracle-cicadm-db-service" /> </beans>  <beans>     <bean id="entitymanagerfactory"         class="org.springframework.orm.jpa.localcontainerentitymanagerfactorybean">         <property name="datasource" ref="actmondatasource" />         <property name="persistenceunitname" value="activity-monitor" />         <property name="jpavendoradapter" ref="jpavendoradapter"/>         <property name="jpaproperties">             <value>                 hibernate.format_sql=true             </value>         </property>     </bean>      <bean id="transactionmanager"         class="org.springframework.orm.jpa.jpatransactionmanager">         <property name="entitymanagerfactory" ref="entitymanagerfactory" />     </bean> </beans>  <beans profile="default">     <jee:jndi-lookup id="datasource"         jndi-name="jdbc/actmon" /> </beans>  <beans profile="cloud">     <cloud:data-source id="actmondatasource" service-name="postgres-actmon-db-service" /> </beans>  <beans profile="default,cloud">     <bean id="jpavendoradapter"         class="org.springframework.orm.jpa.vendor.hibernatejpavendoradapter">         <property name="database" value="postgresql" />     </bean> </beans> 

output cf when deploy https://gist.github.com/anonymous/3986a1a7cea4f20c096e. note skipping auto re-configuration of javax.sql.datasources

first of all, post thomas pretty old, , references deprecated support library. instead of org.cloudfoundry:cloudfoundry-runtime:0.8.1 dependency, should use spring cloud connectors dependencies instead.

you can follow instructions provided using xml configuration spring cloud connectors. multiple services of same type, need specify name of service each bean. following example, , assuming created 2 cf database services named inventory-db , customer-db, might this:

<bean id="entitymanagerfactory"    class="org.springframework.orm.jpa.localcontainerentitymanagerfactorybean">     <property name="datasource" ref="inventory-datasource" />     <property name="persistenceunitname" value="activity-monitor" />     <property name="jpavendoradapter" ref="jpavendoradapter"/>     <property name="jpaproperties">         <value>             hibernate.format_sql=true         </value>     </property> </bean>  <beans profile="cloud">     <cloud:data-source id="inventory-datasource" service-name="inventory-db">     <cloud:data-source id="customer-datasource" service-name="customer-db"> </beans> 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

php - Find a regex to take part of Email -

javascript - Function overwritting -