Gradle Fat Jar插件和Spring:从类路径资源

时间:2016-01-11 14:02:12

标签: java xml spring gradle spring-ldap

使用等级胖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
}

运行此应用程序(包含所有依赖项的胖jar)如下:

-bash-3.2$ java -Dconf.properties=/app/home/wasa/sat/bin/app.properties -jar app-all-1.0.jar

两个想法发生了:

首先收到spring bootstrap start消息:

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]

然后过了一会儿,错误/异常会引起如下所述:

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)

我也尝试下载spring-beans.xsd文件定义并将其包含在我项目的resources文件夹中但没有成功。

我正在加载spring xml配置文件,如下所示:

public static void main(String[] args) throws Exception {
    AbstractApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
    getAllActiveUsersInPeople(context);
}

我的appicationContext.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">

有人遇到类似的问题或解决此问题的可能解决方案吗?

由于

0 个答案:

没有答案