Java Gradle Fat Jar插件和Spring:从类路径资源加载XML bean定义时出错

Java Gradle Fat Jar插件和Spring:从类路径资源加载XML bean定义时出错,java,xml,spring,gradle,spring-ldap,Java,Xml,Spring,Gradle,Spring Ldap,使用grade fat jar插件构建我的应用程序后,如下所示: task fatJar(type: Jar) { manifest { attributes 'Implementation-Title': 'PACMAN', 'Implementation-Version': version, 'Main-Class': 'com.y.y.z.Mainclass' } baseName =

使用grade fat jar插件构建我的应用程序后,如下所示:

task fatJar(type: Jar) {
    manifest {
        attributes 'Implementation-Title': 'PACMAN',
                'Implementation-Version': version,
                'Main-Class': 'com.y.y.z.Mainclass'
    }
    baseName = project.name + '-all'
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
}
11/01/2016 11:42:12 org.springframework.beans.factory.xml.XmlBeanDefinitionReader warning
Ignored XML validation warning
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 
'http://www.springframework.org/schema/beans/spring-beans.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>.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
...
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:287)
        at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:76)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadDocument(XmlBeanDefinitionReader.java:429)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:391)
public static void main(String[] args) throws Exception {
    AbstractApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
    getAllActiveUsersInPeople(context);
}
并按如下方式运行此应用程序(具有所有依赖项的胖jar):

-bash-3.2$ java -Dconf.properties=/app/home/wasa/sat/bin/app.properties -jar app-all-1.0.jar
发生了两种情况:

首先收到spring引导启动消息:

11/01/2016 11:38:59 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@11f23e5: startup date 
[Mon Jan 11 11:38:59 BRST 2016]; root of context hierarchy

11/01/2016 11:39:00 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [applicationContext.xml]
然后过了一段时间,该错误/异常如以下所述出现:

task fatJar(type: Jar) {
    manifest {
        attributes 'Implementation-Title': 'PACMAN',
                'Implementation-Version': version,
                'Main-Class': 'com.y.y.z.Mainclass'
    }
    baseName = project.name + '-all'
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
}
11/01/2016 11:42:12 org.springframework.beans.factory.xml.XmlBeanDefinitionReader warning
Ignored XML validation warning
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 
'http://www.springframework.org/schema/beans/spring-beans.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>.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
...
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:287)
        at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:76)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadDocument(XmlBeanDefinitionReader.java:429)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:391)
public static void main(String[] args) throws Exception {
    AbstractApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
    getAllActiveUsersInPeople(context);
}
My AppificationContext.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:ldap="http://www.springframework.org/schema/ldap"
       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 http://www.springframework.org/schema/ldap http://www.springframework.org/schema/ldap/spring-ldap.xsd">

有人有类似的问题或可能的解决方案来解决此问题


谢谢

您已经将spring jar添加到您的类路径中了吗?@Jens classpath with gradle fat jar?所有库都在结果jarManifest版本中:1.0 Rsrc类路径:./aopalliance-1.0.jar commons-lang-2.3.jar commons-l ogging-1.2.jar guava-19.0-rc1.jar logback-classic-1.1.3.jar logback-c ore-1.1.1.1.3.jar pacman.jar slf4j-api-1.7.12.jarspring-aop-4.2.1.RELEASE.jar spring-beans-4.2.1.RELEASE.jar spring-context-4.2.1.RELEASE.jar spring-core-4.2.1.RELEASE.jar spring-expression-4.2.1.RELEASE.jar spring-ldap-core-2.0.3.RELEASE SE.jar spring-tx-3.2.13.RELEASE.jar类路径:。Rsrc主类:com.tim.pcs.app.PacBiru主类:org.eclipse.jdt.jarinjarloader.jarrscloader