使用嵌入式jetty将spring mvc作为独立应用程序运行时出错

时间:2014-04-02 16:57:46

标签: spring-mvc embedded-jetty maven-assembly-plugin

我有一个主类来运行spring mvc应用程序作为使用jetty的独立应用程序。我使用maven-shade-plugin生成jar文件。

运行jar文件时看到以下错误

org.eclipse.jetty.servlet.ServletHolder$1: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 8 in XML document from ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 8; columnNumber: 106; cvc-elt.1: Cannot find the declaration of element 'beans'.

我的mvc-dispacher-servlet.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:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">

任何人都可以帮助我找不到的东西

1 个答案:

答案 0 :(得分:1)

通过在maven-shade-plugin配置中添加以下内容

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