从Java启动Spring应用程序的异常 [英] Exception starting Spring application from Java

查看:115
本文介绍了从Java启动Spring应用程序的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够使用Maven编译并启动我的Spring项目:

I am able to compile and start my Spring project using Maven:

mvn -e clean compile exec:java -Dexec.mainClass=de.fraunhofer.fkie.tet.vmware.manager.Test

然而,当我组装使用 maven-assembly-plugin (包括 applicationContext.xml )的单个文件中的所有jar,我总是得到一个在 java 执行期间异常

However, when I assemble all jars in a single file using the maven-assembly-plugin (including applicationContext.xml), I always get an Exception during the java execution:

java -cp target/test-jar-with-dependencies.jar:. de.fraunhofer.fkie.tet.vmware.manager.Test

  INFO: Loading XML bean definitions from class path resource [applicationContext.xml]
  Sep 6, 2010 10:37:21 AM org.springframework.util.xml.SimpleSaxErrorHandler warning
  WARNING: Ignored XML validation warning
  org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/context/spring-context.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
  ...
  Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: 
  Line 10 in XML document from class path resource [applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: 
  The matching wildcard is strict, but no declaration can be found for element 'context:annotation-config'.
  ...
  Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: 
  The matching wildcard is strict, but no declaration can be found for element 'context:annotation-config'.

我还尝试附加架构定义,即 spring-context.xsd 等,直接到类路径,但没有任何成功。

I also tried to attach the schema definitions, i.e. spring-context.xsd etc., directly to the classpath, but without any success.

less src/main/resources/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:context="http://www.springframework.org/schema/context"
         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">

      <context:annotation-config />   <!-- wegen '@PostConstruct' -->
  <!--<context:component-scan base-package="de.fraunhofer" />     -->
  ...
  </beans>


推荐答案

Spring命名空间处理程序使用文件解析 /META-INF/spring.schemas /META-INF/spring.handlers 。因为具有这些名称的文件存在于不同的Spring jar中,所以在 maven-assembly-plugin 之后可能只有其中一个保留在目标jar中。

Spring namespace handlers are resolved using files /META-INF/spring.schemas and /META-INF/spring.handlers. Because files with these names exist in different Spring jars, probably only one of them remains in target jar after maven-assembly-plugin.

也许您可以手动合并这些文件并以某种方式配置 maven-assembly-plugin 以使用此合并文件覆盖目标jar中的文件。

Perhaps you may merge these files manually and somehow configure maven-assembly-plugin to overwrite file in target jar with this merged file.

这篇关于从Java启动Spring应用程序的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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