gpt4 book ai didi

java - 像bean方法一样配置brokerURL

转载 作者:行者123 更新时间:2023-12-02 03:34:30 25 4
gpt4 key购买 nike

我需要配置 JMS 发送器。但我必须有机会在属性文件中设置 DNS 名称。我还有应该添加到 DNS 的参数。我决定创建一个 Bean,将完整的 url 返回给代理。但我有一个启动问题。这是我的 XML:

<bean id="path" class="com.promptlink.stbtp.Config" factory-method="getJMSPath"/>


<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" ref="path"/>
</bean>

这是最终链接:

nio://10.20.6.192:9091?connectionTimeout=3000&amp;jms.useAsyncSend=true&amp;wireFormat.tightEncodingEnabled=false 

如果我将链接直接设置为属性值 - 没有问题。 JMS 起步良好。但是当我尝试将链接作为 bean 传递时 - 它崩溃了。异常(exception):

javax.jms.JMSException: Error while attempting to add new Connection to the pool
at org.apache.activemq.jms.pool.PooledConnectionFactory.createJmsException(PooledConnectionFactory.java:251)
at org.apache.activemq.jms.pool.PooledConnectionFactory.createConnection(PooledConnectionFactory.java:210)
at org.apache.activemq.jms.pool.PooledConnectionFactory.createConnection(PooledConnectionFactory.java:189)
at org.apache.activemq.jms.pool.PooledConnectionFactory.start(PooledConnectionFactory.java:271)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1706)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1645)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:140)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:84)
at com.promptlink.stbtp.messaging.NodeMessageDispatcher.getInstance(NodeMessageDispatcher.java:20)
at com.promptlink.stbtp.messaging.NodeMessageDispatcher.sendToWebapp(NodeMessageDispatcher.java:33)
at com.promptlink.stbtp.Config.init(Config.java:170)
at com.promptlink.stbtp.App.main(App.java:159)
Caused by: javax.jms.JMSException: Could not create Transport. Reason: java.lang.IllegalArgumentException: Invalid connect parameters: {amp;wireFormat.tightEncodingEnabled=false, amp;jms.useAsyncSend=true}
at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:36)
at org.apache.activemq.ActiveMQConnectionFactory.createTransport(ActiveMQConnectionFactory.java:317)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:330)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:303)
at org.apache.activemq.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:243)
at org.apache.activemq.jms.pool.PooledConnectionFactory.createConnection(PooledConnectionFactory.java:259)
at org.apache.activemq.jms.pool.PooledConnectionFactory$1.makeObject(PooledConnectionFactory.java:104)
at org.apache.activemq.jms.pool.PooledConnectionFactory$1.makeObject(PooledConnectionFactory.java:84)
at org.apache.commons.pool.impl.GenericKeyedObjectPool.addObject(GenericKeyedObjectPool.java:1748)
at org.apache.activemq.jms.pool.PooledConnectionFactory.createConnection(PooledConnectionFactory.java:206)
... 24 more
Caused by: java.lang.IllegalArgumentException: Invalid connect parameters: {amp;wireFormat.tightEncodingEnabled=false, amp;jms.useAsyncSend=true}
at org.apache.activemq.transport.TransportFactory.doConnect(TransportFactory.java:122)
at org.apache.activemq.transport.TransportFactory.connect(TransportFactory.java:64)
at org.apache.activemq.ActiveMQConnectionFactory.createTransport(ActiveMQConnectionFactory.java:315)
... 32 more

那么我做错了什么,如何解决这个问题?我所需要的只是将 url 传递给 JMS 代理。

最佳答案

这与配置上下文有关。当您在 XML 中指定值时这&被正确解码为&由 XML 解析器。因此传递给brokerURL属性的实际值将是nio://10.20.6.192:9091?connectionTimeout=3000&jms.useAsyncSend=true&wireFormat.tightEncodingEnabled=false

这是因为&是XML中的特殊字符,需要转义

使用代码生成 URL 时,请确保使用正确的格式

nio://10.20.6.192:9091?connectionTimeout=3000&jms.useAsyncSend=truewireFormat.tightEncodingEnabled=false

关于java - 像bean方法一样配置brokerURL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37596735/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com