“无法找到Spring NamespaceHandler”错误 [英] "unable to locate Spring NamespaceHandler" error

查看:117
本文介绍了“无法找到Spring NamespaceHandler”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Spring创建一个独立的Sava应用程序来处理JDBC访问。该应用程序在每次测试中都能正常工作,我决定需要一个jar来部署我们的客户。

I'm creating a stand-alone Sava application with Spring, to handle the JDBC access. The application works fine on every test and I decided that I need a jar to be deployed our clients.

他们的类路径中可能没有弹簧,所以我使用了maven- assembly-plugin用于处理带有依赖项的jar创建。

They might not have spring in their classpath, so I used maven-assembly-plugin to handle the jar creation with dependencies.

但是当我尝试运行应用程序时:

However when I try to run the application:

java -jar target/myproject-0.0.1-SNAPSHOT-jar-with-dependencies.jar

会抛出以下错误:

Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/p]
Offending resource: class path resource [applicationContext.xml]

at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80)
...and so on to the database access class of this project.

applicationContext.xml文件位于projectbase / src / main / resources中。并将其置于目标/包名称基础。

The applicationContext.xml file is in projectbase/src/main/resources. And its placed at target/packagename base.

applicationContext.xml

The applicationContext.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"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context-3.0.xsd">


    <bean id="dataSourceDesenv" class="org.apache.commons.dbcp.BasicDataSource"... />

    <bean id="simpleJdbcDaoSupport" class="org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport"
      p:dataSource-ref="dataSourceDesenv" />

    <bean id="simpleJdbcTemplate" class="org.springframework.jdbc.core.simple.SimpleJdbcTemplate">
        <constructor-arg ref="dataSourceDesenv" />
    </bean>

</beans>


推荐答案

我发现错误,错误在于< a href =http://jira.codehaus.org/browse/MASSEMBLY-360 =noreferrer> maven-assembly插件中未修复的错误。
我使用了以下解决方法:

I found the error, the bug lies in an unfixed bug in the maven-assembly plugin. I used the following workaround:

首先在我的pom中注释掉了maven-assembly代码。然后我使用maben-dependency-plugin将依赖项复制到目标的lib文件夹中:

First commented out the maven-assembly code in my pom. Then I copied the dependencies to a lib folder at the target using the maben-dependency-plugin:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>copy-dependencies</id>
            <phase>package</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.directory}/lib</outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

然后我使用maven-jar-plugin来设置我的可执行jar:

Then I used the maven-jar-plugin to setup my executable jar:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.3.1</version>
            <configuration>
                <archive>
                    <index>true</index>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>org.foo.myproject.App</mainClass>
                    </manifest>
                    <manifestEntries>
                        <mode>development</mode>
                        <url>${pom.url}</url>
                        <key>value</key>

                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>

最后,我创建了一个bash脚本,该脚本与运行我的app及其libs的应用程序一起部署提供参数:

Finally I created a bash script that is deployed with the application that runs my app with its libs and any provided arguments:

java -cp lib/*:myproject-0.0.1-SNAPSHOT.jar org.foo.myproject.App $@

我应该在python中构建应用程序= /

I should have built the app in python =/

这篇关于“无法找到Spring NamespaceHandler”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆