当前位置: 首页 > 知识库问答 >
问题:

无法找到XML模式命名空间的Spring NamespaceHandler[http://activemq.apache.org/schema/core]

仉嘉泽
2023-03-14

我在使用activeMQ作为JMS提供程序运行我的Spring JMS项目时遇到了麻烦。

线程"main"中的异常org.springframework.beans.factory.parsing.Bean定义解析异常:配置问题:无法定位Spring N amespaceHandler for XML模式名称空间[http://activemq.apache.org/schema/core]违规资源:类路径资源[spring.xml]

任何建议都将不胜感激。以下是代码:

Springxml

<?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)

共有2个答案

曾航
2023-03-14

需要验证的一些事情:

如果使用maven:执行干净的安装

如果你用爆炸的libs创建了一场战争,这可能是个问题,因为它会覆盖amq的配置、服务和xsd文件

你能发pom吗。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"
    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>
钱志义
2023-03-14

更新

库文件夹结构

我没有用maven。

 类似资料: