【发布时间】:2017-03-28 19:16:55
【问题描述】:
【问题讨论】:
-
我删除了批处理文件标签。我正在使用 boot- 1.5.2.RELEASE 版本
标签: spring spring-boot jndi
【问题讨论】:
标签: spring spring-boot jndi
@Configuration
public class Config {
@Value("${spring.datasource.primary.jndi-name}")
private String primaryJndiName;
@Value("${spring.datasource.secondary.jndi-name}")
private String secondaryJndiName;
@Primary
@Bean(destroyMethod = "") // destroy method is disabled for Weblogic update app ability
public DataSource primaryDs() {
JndiDataSourceLookup lookup = new JndiDataSourceLookup();
return lookup.getDataSource(primaryJndiName);
}
@Bean(destroyMethod = "") // destroy method is disabled for Weblogic update app ability
public DataSource secondaryDs() {
JndiDataSourceLookup lookup = new JndiDataSourceLookup();
return lookup.getDataSource(secondaryJndiName);
}
}
【讨论】:
我以这种方式实现并且它正在工作
您可以将您的 jndi 值放在一个属性文件中,然后将该属性文件加载到您的 bean defination.xml 中
jndi.properties
#JNDI property for job repository
job.repository.db.connection=jdbc/pgDB
#JNDI property for application
application.db.connection=jdbc/db2Conn
Bean-defination.xml
<bean id="propertyPlaceholderConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath*:/properties/jndi.properties</value>
</list>
</property>
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
</bean>
<bean id="jobRepoDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="${job.repository.db.connection}" />
</bean>
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="${application.db.connection}" />
</bean>
【讨论】: