我正在尝试为连接到大黄蜂Q的驼峰应用程序编写JUnit测试。配置如下。该应用程序在容器中运行良好。
在实际应用中,我使用了带有保险丝6.3的嵌入式hornetQ。连接工厂以独立完整XML定义,我在java:/ConnectionFactory
中使用JNDIObjectfactorybean
。
我收到以下错误:
引起:org.springframework.beans.factory.BeanCreationException: 创建名为' jmsConnectionFactory'的bean时出错在课堂上定义 path资源[META-INF / spring / bean-declarations.xml]:调用 init方法失败;嵌套异常是javax.naming.NamingException: 方案java无法识别
独立的完整xml消息传递子系统配置:
<jms-connection-factories>
<connection-factory name="InVmConnectionFactory">
<connectors>
<connector-ref connector-name="in-vm"/>
</connectors>
<entries>
<entry name="java:/ConnectionFactory"/>
</entries>
</connection-factory>
<connection-factory name="RemoteConnectionFactory">
<connectors>
<connector-ref connector-name="netty"/>
</connectors>
<entries>
<entry name="java:jboss/exported/jms/RemoteConnectionFactory"/>
</entries>
</connection-factory>
<pooled-connection-factory name="hornetq-ra">
<transaction mode="xa"/>
<connectors>
<connector-ref connector-name="in-vm"/>
</connectors>
<entries>
<entry name="java:/JmsXA"/>
</entries>
</pooled-connection-factory>
</jms-connection-factories>
hornetQ JMS组件的Bean声明:
<bean id="jmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:/ConnectionFactory" />
</bean>
<bean id="hornetq" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory" ref="jmsConnectionFactory" />
</bean>
为了模拟HornetQ服务器,我在测试资源中添加了以下hornerQ配置,如下所示。
hornetq-configuration.xml文件:
<configuration xmlns="urn:hornetq">
<paging-directory>target/data/paging</paging-directory>
<bindings-directory>target/data/bindings</bindings-directory>
<persistence-enabled>false</persistence-enabled>
<journal-directory>target/data/journal</journal-directory>
<journal-min-files>10</journal-min-files>
<large-messages-directory>target/data/large-messages</large-messages-directory>
<security-enabled>false</security-enabled>
<connectors>
<connector name="invm-connector">
<factory-class>org.hornetq.core.remoting.impl.invm.InVMConnectorFactory</factory-class>
</connector>
</connectors>
<acceptors>
<acceptor name="invm-acceptor">
<factory-class>org.hornetq.core.remoting.impl.invm.InVMAcceptorFactory</factory-class>
</acceptor>
</acceptors>
</configuration>
hornetq-jms.xml:
<configuration xmlns="urn:hornetq">
<connection-factory name="ConnectionFactory">
<connectors>
<connector-ref connector-name="invm-connector" />
</connectors>
<entries>
<entry name="java:/ConnectionFactory" />
</entries>
</connection-factory>
<queue name="TEST.QUEUE">
<entry name="TEST.QUEUE" />
</queue>
</configuration>
运行JUnit时的错误详细信息:
java.lang.IllegalStateException:无法加载ApplicationContext org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:103) 在 org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:122) 在 org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:160) 在 org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:101) 在 org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321) 在 org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner $ 1.runReflectiveCall(SpringJUnit4ClassRunner.java:288) 在 org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 在 org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:284) 在 org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231) 在 org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88) 在org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:238)at org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:63)at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)at at org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:53)at at org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:229)at at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) 在 org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) 在org.junit.runners.ParentRunner.run(ParentRunner.java:309)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174) 在 org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) 在 org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) 引起:org.springframework.beans.factory.BeanCreationException: 创建名为&#39; jmsConnectionFactory&#39;的bean时出错在课堂上定义 path资源[META-INF / spring / bean-declarations.xml]:调用 init方法失败;嵌套异常是javax.naming.NamingException: 方案java无法识别 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1514) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) 在 org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:293) 在 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) 在 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290) 在 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191) 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:618) 在 org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:938) 在 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) 在 org.apache.camel.test.spring.CamelSpringTestContextLoader.loadContext(CamelSpringTestContextLoader.java:147) 在 org.apache.camel.test.spring.CamelSpringTestContextLoader.loadContext(CamelSpringTestContextLoader.java:84) 在 org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:69) 在 org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:95) ... 25更多引起:javax.naming.NamingException:scheme java not 承认 org.apache.camel.util.jndi.JndiContext.lookup(JndiContext.java:218) 在javax.naming.InitialContext.lookup(InitialContext.java:417)at org.springframework.jndi.JndiTemplate $ 1.doInContext(JndiTemplate.java:154) 在 org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87) 在 org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152) 在 org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178) 在 org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95) 在 org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105) 在 org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:231) 在 org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:217) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1573) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1511) ......还有38个
我错过了什么吗?