无法找到XML模式名称空间的Spring NamespaceHandler [http://activemq.apache.org/schema/core]
我无法运行我的spring jms项目与activeMQ作为JMS提供程序。收到错误:在线程无法找到XML模式名称空间的Spring NamespaceHandler [http://activemq.apache.org/schema/core]
异常“主要” org.springframework.beans.factory.parsing.BeanDefinitionParsingException:配置问题:找不到春天ñ amespaceHandler XML模式命名空间[http://activemq.apache.org/schema/core] 违犯的资源:类路径的资源[春天.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类
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)
一些事情来验证:如果您使用的Maven
:执行,如果你创建具有分解库一战一个干净的安装
,这可能是因为它的问题覆盖CONFIGS,服务的amq &春天的XSD文件...
你可以张贴的pom.xml &战争结构的libs文件夹&确认是否使用或不战争前ploded。
或者改变你的定义是这样的:
<?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" 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"> <bean id="mqConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"> <property name="brokerURL" value="tcp://Toshiba:61616" /> </bean> <bean id="topic1" class="org.apache.activemq.command.ActiveMQTopic"> <property name="physicalName" value="chattopic" /> </bean>
请参阅下面的更新的答案。出于某种原因,我无法在我的帖子中更新。 – JoeZ
你是如何生成战争文件的?我将libs文件夹结构放入战争文件 –
您是如何生成战争文件的?我将libs文件夹结构添加到war文件中 –
您在服务器或主执行器上运行项目吗? –
我在eclipse中将项目导出为jar文件,然后从powershell运行jar – JoeZ
我已经更新了我的答案 –