Maven和Spring =无法创建应用程序上下文:无法找到Spring NamespaceHandler [英] Maven and Spring = Unable to create application context: Unable to locate Spring NamespaceHandler

查看:88
本文介绍了Maven和Spring =无法创建应用程序上下文:无法找到Spring NamespaceHandler的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据问题和

As per this question and this question, I'm getting the following error:

Unable to create application context: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/context]
Offending resource: class path resource [floodstream-mastercontrol.conf.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)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:284)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1332)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1325)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:136)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:93)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212)
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:126)
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:92)
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:465)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:395)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at com.floodstream.wowza.mastercontrol.ServerListener.onServerCreate(ServerListener.java:30)
    at com.wowza.wms.server.Server.notifyServerCreate(Unknown Source)
    at com.wowza.wms.server.Server.start(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at com.wowza.wms.bootstrap.Bootstrap.startServer(Unknown Source)
    at com.wowza.wms.bootstrap.Bootstrap.main(Unknown Source)

很明显,这是由于Maven中的一些错误,所以这是我相关的POM:

Evidently, this is because of some bug in Maven, so here's my relevant POM:

<project>
    <!-- dependencies omitted for brevity -->

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <includeScope>runtime</includeScope>
                            <outputDirectory>${project.build.directory}/dependencies</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.2.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <phase>package</phase>
                        <configuration>
                            <descriptorRefs>
                                <descriptorRef>jar-with-dependencies</descriptorRef>
                            </descriptorRefs>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

这是我的应用程序上下文:

Here is my application context:

<?xml version="1.0"?>
<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        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">

    <context:load-time-weaver/>
    <context:spring-configured/>

    <!-- beans omitted for brevity -->
</beans>

因此,目标是将事情组合成一个JAR,但我认为这可能是问题所在.有人可以说明问题是什么以及如何解决吗?其他提到的问题具有不同的设置和目标,因此我无法完全遵循他们的观点.

So, the goal is to combine things down into one JAR, but I think that might be the problem. Can someone explain what the problem is and how I can solve it? The other referenced questions had a different setup and goal, so I can't exactly follow their lead.

推荐答案

实际上,这不是Maven中的错误.这是构建uber-jar的简单方法的结果. Spring名称空间处理程序在META-INF/spring.handlers文件中注册.一些spring模块具有自己的名称空间,因此您可以在许多不同的spring jar中找到该文件.如果在构建uber-jar时不将这些文件合并在一起,则最终会导致其中之一覆盖所有其他文件,这显然意味着您将缺少一些处理程序.任何允许您指定带有所有必需处理程序的spring.handlers文件的机制都可以使用.建立自己的工具并确保将其用于最终工件中是一种方法.

It's not a bug in maven, really. It's the result of a simplistic approach to building an uber-jar. Spring namespace handlers are registered in a file at META-INF/spring.handlers. Several of the spring modules have their own namespaces, and therefore you'll find this file in many different spring jars. If you don't merge these files together when building your uber-jar, you'll end up with one of them overwriting all the others, which obviously means you'll be missing some handlers. Any mechanism that lets you specify a spring.handlers file with all the required handlers in it will work. Building your own and ensuring it gets used in the final artifact would be one way.

这篇关于Maven和Spring =无法创建应用程序上下文:无法找到Spring NamespaceHandler的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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