Spring配置问题:无法找到用于XML模式名称空间的Spring NamespaceHandler,令人讨厌的资源:类路径 [英] Spring Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace, Offending resource: class path

查看:123
本文介绍了Spring配置问题:无法找到用于XML模式名称空间的Spring NamespaceHandler,令人讨厌的资源:类路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我陷入无法解决的问题.我有支持Quartz Scheduler和Gradle的Spring Batch应用程序.本地一切正常.但是,当我使用Gradle构建jar并尝试在异常下运行它时,会抛出异常.

I am stuck at an issue which I am unable to resolve. I have spring batch application powered with Quartz scheduler and Gradle. Everything is working fine locally. But when I'm building the jar using Gradle and trying to run it below exceptions are thrown.

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文件.

I tried to place the xsd file locally, but still getting this error. Below is my application.context file.

<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文件.

I am using gradle to build the jar file and copying all the dependencies within the Jar. Below is my build.gradle file.

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"]
}

我的主班

    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进行哪些更改.我正在使用bat文件和-jar命令运行jar.请帮助我,无法取得任何进展,我只是被困住了.

I am just not sure, what changes I am supposed to make to run the executable jar. I am running the jar using bat file with -jar command. Please help me guys, unable to make any progress, I am just stuck.

推荐答案

发布后,您的URL错误.他们缺少/.正确的标题应该是:

As posted, your URLs are wrong. They are missing a /. The correct header should be:

<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之间的/.

Your configuration above was missing the / between context and spring-context-4.3.xsd.

这篇关于Spring配置问题:无法找到用于XML模式名称空间的Spring NamespaceHandler,令人讨厌的资源:类路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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