gpt4 book ai didi

java - 将 Spring XML 上下文移至 Groovy

转载 作者:行者123 更新时间:2023-12-01 12:05:56 25 4
gpt4 key购买 nike

我正在尝试将我的简单 Spring 集成应用程序从 XML 上下文移动到 Groovy 上下文。不幸的是,找不到任何有用的示例如何在 Groovy 上下文中使用 namespace 。我从最简单的部分开始,入站网关与MQ绑定(bind):

<bean id="jmsFactory" class="org.apache.activemq.pool.PooledConnectionFactory" destroy-method="stop">
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="<brokerUrl>"/>
</bean>
</property>
</bean>

<int:channel id="plainRequestChannel"/>
<int:channel id="errorChannel"/>
<int:channel id="plainReplyChannel"/>

<int-jms:inbound-gateway id="gateway" request-destination-name="QUEUE.IN"
default-reply-queue-name="QUEUE.OUT"
request-channel="plainRequestChannel"
error-channel="errorChannel"
reply-channel="plainReplyChannel"
connection-factory="jmsFactory"/>

我的 Groovy 相当于此上下文(不起作用):

package spring4

import org.apache.activemq.jms.pool.PooledConnectionFactory
import org.apache.activemq.spring.ActiveMQConnectionFactory;

beans {
xmlns intjms:"http://www.springframework.org/schema/integration/jms"
xmlns integration:"http://www.springframework.org/schema/integration"

amqConnectionFactory (ActiveMQConnectionFactory) {
brokerURL = "<brokerUrl>"
}

jmsFactory (PooledConnectionFactory) {bean ->
bean.destroyMethod = 'stop'
connectionFactory = ref('amqConnectionFactory')
}

integration.channel(id:'plainRequestChannel')
integration.channel(id:'plainReplyChannel')
integration.channel(id:'errorChannel')

intjms.'inbound-gateway'(
id:"gateway",
'request-destination-name': "QUEUE.IN",
'default-reply-queueName': "QUEUE.OUT",
'request-channel': ref('plainRequestChannel'),
'error-channel': ref('errorChannel'),
'reply-channel': ref('plainReplyChannel'),
'connection-factory': ref('jmsFactory')
)
}

正如我提到的,它不起作用。错误:

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.jms.listener.DefaultMessageListenerContainer#0': Cannot resolve reference to bean '<jmsFactory>' while setting bean property 'connectionFactory'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named '<jmsFactory>' is defined
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1469)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:762)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.context.support.GenericGroovyApplicationContext.<init>(GenericGroovyApplicationContext.java:151)
at my.pack.integration.SpringGroovyBootstraper.main(SpringGroovyBootstraper.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named '<jmsFactory>' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:694)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1157)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:280)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
... 19 more

请问我做错了什么?另外,如果您向我推荐任何相关教程/示例/文档的链接,我将不胜感激

最佳答案

你看过groovy dsl吗? ?

它最近没有太多 Activity ,但它可能会给您一些指示(它有一个 JMS 模块)。

您可能还想查看新的(积极维护的)Java DSL .

关于java - 将 Spring XML 上下文移至 Groovy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27601744/

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