相关疑难解决方法(0)

使用JNDI在Spring Boot中配置多个DataSource

我要管理多发使用您的应用程序服务器的内置功能DataSource和使用JNDI访问它.我使用Spring JPA数据进行Spring启动.

我能够为单个数据源配置application.properties: -

spring.datasource.jndi-name=jdbc/customers
Run Code Online (Sandbox Code Playgroud)

我在context.xml文件中的配置如下: -

<Resource name="jdbc/customer" auth="Container" type="javax.sql.DataSource"
               maxTotal="100" maxIdle="30" maxWaitMillis="10000"
               username="root" password="root" driverClassName="com.mysql.jdbc.Driver"
               url="jdbc:mysql://localhost:3306/customer"/>
Run Code Online (Sandbox Code Playgroud)

一切正常.

但是当我无法配置两个数据源时.

我确定在context.xml文件中的配置: -

 <Resource name="jdbc/customer" auth="Container" type="javax.sql.DataSource"
                   maxTotal="100" maxIdle="30" maxWaitMillis="10000"
                   username="root" password="root" driverClassName="com.mysql.jdbc.Driver"
                   url="jdbc:mysql://localhost:3306/customer"/>

 <Resource name="jdbc/employee" auth="Container" type="javax.sql.DataSource"
                   maxTotal="100" maxIdle="30" maxWaitMillis="10000"
                   username="root" password="root" driverClassName="com.mysql.jdbc.Driver"
                   url="jdbc:mysql://localhost:3306/employee"/>
Run Code Online (Sandbox Code Playgroud)

我对application.properties文件配置有疑问.

我尝试了以下选项但没有成功: -

spring.datasource.jndi-name=jdbc/customers,jdbc/employee
Run Code Online (Sandbox Code Playgroud)

有关多个数据源的JNDI,请告诉我有关Spring启动的任何详细信息.我好几天都在寻找这种配置.任何形式的建议或评论都会受到高度赞赏.

根据Spring Boot文档进行第二次试验

spring.datasource.primary.jndi-name=jdbc/customer
spring.datasource.secondary.jndi-name=jdbc/project
Run Code Online (Sandbox Code Playgroud)

配置类.

@Bean
@Primary
@ConfigurationProperties(prefix="datasource.primary")
public DataSource primaryDataSource() {
    return DataSourceBuilder.create().build();
}

@Bean
@ConfigurationProperties(prefix="datasource.secondary")
public DataSource secondaryDataSource() {
    return DataSourceBuilder.create().build();
}
Run Code Online (Sandbox Code Playgroud)

该应用程序无法启动.虽然tomcat服务器正在启动.日志中不会打印错误.

第三次试验: - …

java spring jndi spring-data spring-boot

8
推荐指数
3
解决办法
3万
查看次数

将 Spring 的 JndiObjectFactoryBean 转换为用于 Solace-MQ JMS 的 ConnectionFactory 时出错

我对 Camel Context 有一个很好的工作 XML 配置,它使用 JNDI 和 Spring

后来 Solace.JndiObjectFactoryBean 被用作 connectionFactory

<bean id="Solace.JmsComponent" class="  on">
    <property name="connectionFactory" ref="Solace.JndiObjectFactoryBean" />
    <property name="destinationResolver" ref="Solace.JndiDestinationResolver" />
</bean>
Run Code Online (Sandbox Code Playgroud)

我正在尝试将其转换为从org.apache.camel.spring.javaconfig.CamelConfiguration. 但是有一个问题。当我尝试在 JMS 组件 component.setConnectionFactory(getJndiObjectFactoryBean()); 上设置连接工厂时;getJndiObjectFactoryBean(),我得到一个编译时异常:

The method setConnectionFactory(ConnectionFactory) in the type JmsComponent 
is not applicable for the arguments (JndiObjectFactoryBean)
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试将从 getJndiObjectFactoryBean 显式返回的 JndiObjectFactoryBean 强制转换为 SolConnectionFactory 时,出现运行时错误

016-02-05 17:39:09,234|[localhost-startStop-1]|[]|[]|[ERROR] web.context.ContextLoader [line:307] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'getJMSConfiguration' defined in class path resource [com//camel
/CamelRoutesConfig.class]: Instantiation of bean failed; …
Run Code Online (Sandbox Code Playgroud)

jms apache-camel spring-jms solace-mq solace

4
推荐指数
1
解决办法
4582
查看次数