简体   繁体   English

Spring Boot JMS InitialContext

[英]spring boot jms initialcontext

I'm looking to configure a Spring boot application to do a JNDI lookup (configure initialContext) of the connection. 我想配置一个Spring Boot应用程序来进行连接的JNDI查找(配置initialContext)。 This is running as a standalone Spring boot application (not on an application server). 它作为独立的Spring Boot应用程序运行(不在应用程序服务器上)。 I have the following which works fine, although I provide all the configuration values myself (not setting timeouts/etc here, but would normally be): 尽管我自己提供了所有配置值(此处未设置超时/ etc,但通常是这样),但我的以下各项仍能正常工作:

@Bean
public ConnectionFactory tibJmsConnectionFactory() throws JMSException {
    TibjmsConnectionFactory myFac = new TibjmsConnectionFactory();
    myFac.setServerUrl("tcp://xxxxx:7222");
    myFac.setUserName("xxxxxxx");
    myFac.setUserPassword("xxxxxx");
    return myFac;
}

@Bean
public JmsListenerContainerFactory<?> myFactory(ConnectionFactory connectionFactory,
                                                DefaultJmsListenerContainerFactoryConfigurer configurer) {
    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    configurer.configure(factory, connectionFactory);
    return factory;
}

When running on an application server, you can set up a JNDI context URL to pull configuration values (timeouts/etc) from an external connection (in our case, the source JMS server) by specifying an "Initial Context Factory" on the JNDI connection. 在应用程序服务器上运行时,可以通过在JNDI连接上指定“初始上下文工厂”来设置JNDI上下文URL,以从外部连接(在本例中为源JMS服务器)中提取配置值(超时/等)。 。 How I can do the equivalent from a Spring boot application not running on an application server? 如何从不在应用程序服务器上运行的Spring Boot应用程序中进行等效操作?

Your tibJmsConnectionFactory() isn't returning connection factory from server. 您的tibJmsConnectionFactory()没有从服务器返回连接工厂。 You're just instantiating it with some properties. 您只是使用一些属性实例化了它。 You've to do context lookup. 您必须进行上下文查找。

    Context ctx = new InitialContext(env);      

    TibjmsConnectionFactory connectionFactory = (TibjmsConnectionFactory) ctx.lookup("factoryName");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM