【问题标题】:Spring boot - 2 JNDI configurationSpring boot - 2 JNDI配置
【发布时间】:2017-03-28 19:16:55
【问题描述】:

贴出我当前的配置

【问题讨论】:

  • 我删除了批处理文件标签。我正在使用 boot- 1.5.2.RELEASE 版本

标签: spring spring-boot jndi


【解决方案1】:
@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);
   }
}

【讨论】:

    【解决方案2】:

    我以这种方式实现并且它正在工作

    您可以将您的 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-12
      • 2019-03-18
      • 1970-01-01
      • 1970-01-01
      • 2016-08-28
      • 2020-08-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多