我有一个 Spring Integration WAR 组件,我正在更新它以在私有 PCF 中运行。我在应用程序中定义了两个数据源和一个 RabbitMQ 连接工厂。
我看到 Thomas Risberg 的一篇关于使用云命名空间和同时处理多个服务的文章 - https://spring.io/blog/2011/11/09/using-cloud-foundry-services-with-spring-part -3-the-cloud-namespace。这是通过使用@Autowired 和@Qualifier 注释来处理的。
我想知道当我们不是@Autowired 和@Qualifier 注释时如何实现这一点,例如将DataSource 连接到JdbcTemplate 中。这里我们无法指定@Qualifier 注解。
我的应用程序是基于 Spring XML 配置的。我确实有能力在其中一个数据源上使用 @Autowired 和 @Qualifier 注释,但另一个是 JPA 实体管理器。请参阅代码片段。
任何帮助深表感谢。
<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。
更新:这是两个数据源的完整配置,包括使用 DAO 从数据源加载属性的 PropertySourcesPlaceholderConfigurer。
<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>
当我部署https://gist.github.com/anonymous/3986a1a7cea4f20c096e时来自 CF 的输出。请注意,它正在跳过 javax.sql.DataSources 的自动重新配置