我陷入无法解决的问题。我有支持Quartz Scheduler和Gradle的Spring Batch应用程序。本地一切正常。但是,当我使用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"]
}
我的主班
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。请帮助我,无法取得任何进展,我只是被困住了。
发布后,您的URL错误。他们缺少/
。正确的标题应该是:
<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
之间的spring-context-4.3.xsd
。