簡體   English   中英

Spring 配置問題:無法找到 Spring NamespaceHandler for XML 架構命名空間,違規資源:ZA2F2ED4F298EBC2CBB40C2 路徑

[英]Spring Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace, Offending resource: class path

我被困在一個我無法解決的問題上。 我有 spring 批處理應用程序,由 Quartz 調度程序和 Gradle 驅動。 在本地一切正常。 但是,當我使用 Gradle 構建 jar 並嘗試在引發異常的情況下運行它時。

Jun 09, 2020 5:14:01 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@15551852: startup date [Tue Jun 09 17:14:01 IST 2020]; root of context hierarchy
Jun 09, 2020 5:14:01 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [applicationContext.xml]
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 [applicationContext.xml]

        at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:70)
        at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:118)

我試圖將 xsd 文件放在本地,但仍然出現此錯誤。 下面是我的 application.context 文件。

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:batch="http://www.springframework.org/schema/batch"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    spring-beans-4.3.xsd
    http://www.springframework.org/schema/context
    spring-context-4.3.xsd
    http://www.springframework.org/schema/tool
    spring-tool.xsd
    http://www.springframework.org/schema/batch
    spring-batch-3.0.xsd
    http://www.springframework.org/schema/tx 
    spring-tx.xsd">

    <context:component-scan base-package="org.*.*" />

    <bean id="transactionManager"
        class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" />

    <bean id="jobRepository"
        class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
        <property name="transactionManager" ref="traJnsactionManager" />
    </bean>

    <bean id="jobLauncher"
        class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
        <property name="jobRepository" ref="jobRepository" />
    </bean>

    <batch:job id="compareVersion">
      <batch:step id="step1">
        <batch:tasklet ref = "versionComparisonTasklet" />
      </batch:step>
    </batch:job> 

我正在使用 gradle 構建 jar 文件並復制 Jar 中的所有依賴項。 下面是我的 build.gradle 文件。

group "org.*.*"
apply plugin: 'java'

sourceCompatibility = 1.8
version = '1.0'
jar {
    manifest {
        attributes 'Implementation-Title': 'Gradle Quickstart',
        'Implementation-Version': version
    }
    baseName = 'BatchJob'
}

dependencies {
    compile 'com.oracle:ojdbc6:11.2.0.4.0'
    compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
    compile group: 'org.springframework', name: 'spring-core', version: '4.3.12.RELEASE'
    compile group: 'org.springframework', name: 'spring-webmvc', version: '4.3.12.RELEASE'
    compile group: 'org.springframework', name: 'spring-orm', version: '4.3.12.RELEASE'
    compile group: 'org.springframework', name: 'spring-context', version: '4.3.12.RELEASE'
    compile group: 'org.springframework', name: 'spring-context-support', version: '4.3.12.RELEASE'
    compile group: 'org.springframework.batch', name: 'spring-batch-core', version: '3.0.8.RELEASE'
    compile group: 'org.springframework', name: 'spring-oxm', version: '4.3.12.RELEASE'
    compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.9.1'
    compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.9.1'
    compile group: 'org.hibernate', name: 'hibernate-core', version: '5.2.12.Final'
    compile group: 'org.hibernate.validator', name: 'hibernate-validator', version: '6.0.3.Final'
    compile group: 'org.hibernate', name: 'hibernate-c3p0', version: '5.2.12.Final'
    compile group: 'javax.mail', name: 'mail', version: '1.4.4'
    testCompile group: 'junit', name: 'junit', version: '4.+'
    testCompile group: 'org.springframework', name: 'spring-test', version: '4.3.12.RELEASE'
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.2'
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.9.2'
    compile group: 'org.thymeleaf', name: 'thymeleaf-spring4', version: '3.0.9.RELEASE'
    compile group: 'org.thymeleaf', name: 'thymeleaf', version: '3.0.9.RELEASE'
    compile group: 'aopalliance', name: 'aopalliance', version: '1.0'
    compile group: 'cglib', name: 'cglib', version: '2.2'
    compile group: 'asm', name: 'asm', version: '3.1'
    compile group: 'com.sun.xml.bind', name: 'jaxb-impl', version: '2.2.11'
    compile group: 'com.sun.xml.bind', name: 'jaxb-core', version: '2.2.11'
    compile group: 'commons-logging', name: 'commons-logging', version: '1.2'
    compile group: 'com.sun.xml.wss', name: 'xws-security', version: '3.0'
    compile group: 'org.apache.ws.security', name: 'wss4j', version: '1.6.19'
    compile group: 'com.thoughtworks.xstream', name: 'xstream', version: '1.3.1'
    compile group: 'joda-time', name: 'joda-time', version: '2.9.9'

    xjc 'com.sun.xml.bind:jaxb-impl:2.1.12'
    xjc 'com.sun.xml.bind:jaxb-xjc:2.1.12'
    xjc 'javax.xml.bind:jaxb-api:2.2.2'
}



buildDistributionZip {

    into('dist/config/dpw/cdi-org-structure-ws-v1/wsdl') {
        from ("${projectDir}/misc/resources/schemas/cdi-org-structure-ws-v1/wsdl") {
        }
    }
}

test { systemProperties 'property': 'value' }

uploadArchives {
    repositories { flatDir { dirs 'repos'
        } }
}

task copyToJar(type: Jar) {
    manifest {
        attributes 'Implementation-Title': 'Gradle Quickstart',
        'Implementation-Version': version
    }
    baseName = project.name + '-dependencies'
    from {
        configurations.compile.collect {
            it.isDirectory() ? it : zipTree(it)
        }
    }
    with jar
}



jar {
manifest {
        attributes 'Implementation-Title': 'Gradle Quickstart',
        'Implementation-Version': version,
        'Main-Class': 'org..MyJobScheduler'
  }
    baseName = 'batchjob'

  from {
    configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
  }
}


task runBatchJob(type: JavaExec) {
    main = 'org.springframework.batch.core.launch.support.CommandLineJobRunner'
    classpath = sourceSets.test.runtimeClasspath
    args = ["applicationContext.xml", "versionComparisonTasklet"]
}

我的主 Class

    public static void main(String[] args) throws SchedulerException {  
    JobDetail j=JobBuilder.newJob(MyJobBuilder.class).build();  
    Trigger t=TriggerBuilder.newTrigger().withIdentity("CroneTrigger").withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInHours(72).repeatForever()).build();    
    Scheduler s=StdSchedulerFactory.getDefaultScheduler();
    s.start();
    s.scheduleJob(j,t);

    }

我只是不確定,我應該進行哪些更改來運行可執行文件 jar。 我正在使用帶有 -jar 命令的 bat 文件運行 jar。 請幫助我,無法取得任何進展,我只是卡住了。

如發布的那樣,您的網址是錯誤的。 他們缺少/ 正確的 header 應該是:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:batch="http://www.springframework.org/schema/batch"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-4.3.xsd
    http://www.springframework.org/schema/tool
    http://www.springframework.org/schema/tool/spring-tool.xsd
    http://www.springframework.org/schema/batch
    http://www.springframework.org/schema/batch/spring-batch-3.0.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx.xsd">

您上面的配置缺少contextspring-context-4.3.xsd之間的/

我撞到了這篇文章。 希望這對你有一些意義。

https://robert-reiz.com/2011/11/14/832/

它說你應該有transformer配置

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM