我在使用activeMQ作为JMS提供程序运行我的spring jms项目时遇到了麻烦。得到错误:
线程中的异常" main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException:配置问题:无法找到Spring N XML模式命名空间的{amespaceHandler [http://activemq.apache.org/schema/core] 违规资源:类路径资源[spring.xml]
非常感谢任何建议。这是代码:
spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jms="http://www.springframework.org/schema/jms"
xmlns:amq="http://activemq.apache.org/schema/core"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jms
http://www.springframework.org/schema/jms/spring-jms.xsd
http://activemq.apache.org/schema/core
http://activemq.apache.org/schema/core/activemq-core.xsd">
<amq:connectionFactory id="mqConnectionFactory"
brokerURL="tcp://Toshiba:61616" />
<amq:topic id="topic1" physicalName="chattopic" />
<!-- a pooling based JMS provider -->
<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>tcp://localhost:61616</value>
</property>
</bean>
</property>
</bean>
<!-- Spring JMS Template -->
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="mqConnectionFactory" />
</bean>
<!-- Our message listener implementation -->
<bean id="basicJMSChat" class="com.spring.jmsChat.BasicJMSChat">
<property name="chatJMSTemplate" ref="jmsTemplate" />
<property name="jmsTopic" ref="topic1" />
</bean>
<!-- message listener container -->
<bean id="poiMessageListenerContainer"
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="mqConnectionFactory" />
<property name="destination" ref="topic1" />
<property name="messageListener" ref="basicJMSChat" />
<property name="concurrentConsumers" value="1" />
</bean>
<context:annotation-config />
</beans>
java class
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jms.core.JmsTemplate;
public class BasicJMSChat implements MessageListener{
public static void main(String[] args) throws JMSException, IOException {
if (args.length != 1) {
System.out.println("User ID id required!");
} else {
ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
BasicJMSChat basicJMSChat = (BasicJMSChat) context.getBean("basicJMSChat");
TopicConnectionFactory topicConnectionFactory =
(TopicConnectionFactory) basicJMSChat.chatJmsTemplate.getConnectionFactory();
TopicConnection topicConnection =
topicConnectionFactory.createTopicConnection();
basicJMSChat.publish(topicConnection, basicJMSChat.chatTopic, userId);
basicJMSChat.subscriber(topicConnection, basicJMSChat.chatTopic, basicJMSChat);
}
}
}
错误:
Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring N
amespaceHandler for XML schema namespace [http://activemq.apache.org/schema/core]
Offending resource: class path resource [spring.xml]
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:70)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:301)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1408)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1401)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:17
2)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.ja
va:142)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java
:94)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:508)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:392)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:252)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:12
9)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:613)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:514)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.spring.jmsChat.BasicJMSChat.main(BasicJMSChat.java:104)
答案 0 :(得分:0)
要验证的一些事项:
如果您使用maven:执行全新安装
如果你用爆炸的libs创建一个战争,这可能是问题,因为它覆盖了amq&amp;的配置,服务,xsd文件。弹簧...
你可以发布pom.xml&amp; libs文件夹的战争结构&amp;确认你是否使用了战争爆炸。
或者更改您的定义:
<div id="main"> Hover me </div> <div id="show"> Show me on hover </div> <div id="hide"> Hide me on hover </div>
答案 1 :(得分:0)