【问题标题】:Unable to locate Spring Namespace Handler for XML schema namespace (JMS)找不到 XML 模式命名空间 (JMS) 的 Spring 命名空间处理程序
【发布时间】:2014-11-10 19:17:28
【问题描述】:

我正在尝试构建一个可执行的 jar,并在运行时收到以下错误:

INFO:从类路径资源 [spring-app.xml] 加载 XML bean 定义 线程“主”org.springframework.beans.factory.parsing.BeanDefinitionParsingException 中的异常:配置问题:找不到 XML 模式命名空间的 Spring NamespaceHandler [http://www.springframework.org/schema/jms] 违规资源:类路径资源[spring-app.xml]

我的 spring-app.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:jms="http://www.springframework.org/schema/jms"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans      
                http://www.springframework.org/schema/beans/spring-beans.xsd
                http://www.springframework.org/schema/tx 
                http://www.springframework.org/schema/tx/spring-tx.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 class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
    <property name="locations">
        <list>
            <value>/etc/vtb/jndi.properties</value>
        </list>
    </property>
</bean>

<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
    <property name="environment">
        <props>
            <!-- prop key="java.naming.provider.url">jnp://ossprovesbjms01.gmtl.viasat.com:1099</prop-->
            <prop key="java.naming.provider.url">${java.naming.provider.url}</prop>
            <prop key="java.naming.factory.initial">${java.naming.factory.initial}</prop>
            <prop key="java.naming.factory.url.pkgs">${java.naming.factory.url.pkgs}</prop>
        </props>
    </property>
</bean>

<bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiTemplate" ref ="jndiTemplate"/>
    <property name="jndiName" value="ConnectionFactory"/>
</bean>

<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory" ref="connectionFactory"/>
    <property name="pubSubDomain" value="true"/>
    <property name="deliveryPersistent" value="true"/>
    <property name="deliveryMode" value="2"/>
</bean>
<!-- Listener Asynchronous -->
<bean id="beamBalanceListener" class="com.vtblistener.BeamBalanceListener"/>

<jms:listener-container concurrency="5-10">
             <jms:listener destination="Beam_Balance" ref="beamBalanceListener"/>
</jms:listener-container>

我的 pom 如下:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.viasat.nbn.nms</groupId>
<artifactId>vtb-hornetq-listener</artifactId>
<version>1.0.1</version>
<packaging>jar</packaging>
<name>vtb-hornetq-listener</name>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <hornetq.version>2.3.13.Final</hornetq.version>
    <VTB_CONFIG_DIR>/etc/viasat/vtb/</VTB_CONFIG_DIR>
</properties>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.1.3</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>4.0.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-asm</artifactId>
        <version>3.1.4.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>4.0.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.0.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>4.0.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-expression</artifactId>
        <version>4.0.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>4.0.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jms</artifactId>
        <version>4.0.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>4.0.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>4.0.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>4.0.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>4.0.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.hornetq</groupId>
        <artifactId>hornetq-commons</artifactId>
        <version>${hornetq.version}</version>
    </dependency>
    <dependency>
        <groupId>org.hornetq</groupId>
        <artifactId>hornetq-core-client</artifactId>
        <version>${hornetq.version}</version>
    </dependency>
    <dependency>
        <groupId>org.hornetq</groupId>
        <artifactId>hornetq-jms-client</artifactId>
        <version>${hornetq.version}</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.naming</groupId>
        <artifactId>jnpserver</artifactId>
        <version>5.0.3.GA</version>
    </dependency>
    <!-- logback -->
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-core</artifactId>
        <version>1.0.13</version>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.0.13</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.5</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.vtblistener.VtbConsumer</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.vtblistener.VtbConsumer</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id> <!-- this is used for inheritance merges -->
                    <phase>package</phase> <!-- bind to the packaging phase -->
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <finalName>vtb-hornetq-listener</finalName>
</build>

【问题讨论】:

    标签: java spring jms spring-jms


    【解决方案1】:

    这是我添加到我的 maven-shade-plugin 的内容,并且它起作用了。shade 插件提供了附加 jar 文件(如属性和 xml 文件)中存在的资源的选项。 AppendingTransformer 用于普通文件。XmlAppendingTransformer 用于 xml 文件。

    <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
      <resource>META-INF/spring.handlers</resource>
    </transformer>
    <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
      <resource>META-INF/spring.schemas</resource>
    </transformer>
    

    【讨论】:

    • 遇到了同样的问题,使用其他命名空间 (util),但这也适用于我。
    【解决方案2】:

    尝试使用 spring 的版本化 xsd 名称,例如:

    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jms="http://www.springframework.org/schema/jms"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans      
                http://www.springframework.org/schema/beans/spring-beans.xsd
                http://www.springframework.org/schema/tx 
                http://www.springframework.org/schema/tx/spring-tx.xsd
                http://www.springframework.org/schema/context
                http://www.springframework.org/schema/context/spring-context-4.0.xsd
                http://www.springframework.org/schema/jms
                http://www.springframework.org/schema/jms/spring-jms-4.0.xsd">
    

    【讨论】:

      猜你喜欢
      • 2013-10-25
      • 2011-09-29
      • 1970-01-01
      • 1970-01-01
      • 2013-02-25
      • 2015-03-01
      • 2021-12-09
      • 1970-01-01
      相关资源
      最近更新 更多