Spring Batch Admin:无法在字符串值“$ {batch.jdbc.driver}”

时间:2017-03-17 11:42:10

标签: spring-boot spring-integration

我正在尝试将spring批处理与spring batch admin集成。但是我收到此错误Could not resolve placeholder 'batch.jdbc.driver' in string value "${batch.jdbc.driver}"请帮忙。谢谢。

enter code hereorg.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'dataSource' defined in URL [jar:file:/C:/Users/dimakatso.bopape/.gradle/caches/modules-2/files-2.1/org.springframework.batch/spring-batch-admin-manager/2.0.0.BUILD-SNAPSHOT/82b20b57e2c2e2d910d7b2c37bf58c6976071f1/spring-batch-admin-manager-2.0.0.BUILD-SNAPSHOT.jar!/META-INF/spring/batch/bootstrap/manager/data-source-context.xml]: Could not resolve placeholder 'batch.jdbc.driver' in string value "${batch.jdbc.driver}"; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'batch.jdbc.driver' in string value "${batch.jdbc.driver}"
at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:211)
at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:222)
at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:86)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:166)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:678)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:520)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:760)
at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:360)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:306)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1185)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1174)
at za.co.momentum.retail.minion.batch.MinionBatchApplication.main(MinionBatchApplication.java:21)

引起:java.lang.IllegalArgumentException:无法在字符串值“$ {batch.jdbc.driver}”中解析占位符'batch.jdbc.driver'     在org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:174)     在org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126)     at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer $ PlaceholderResolvingStringValueResolver.resolveStringValue(PropertyPlaceholderConfigurer.java:258)     在org.springframework.beans.factory.config.BeanDefinitionVisitor.resolveStringValue(BeanDefinitionVisitor.java:282)     在org.springframework.beans.factory.config.BeanDefinitionVisitor.resolveValue(BeanDefinitionVisitor.java:204)     在org.springframework.beans.factory.config.BeanDefinitionVisitor.visitPropertyValues(BeanDefinitionVisitor.java:141)     在org.springframework.beans.factory.config.BeanDefinitionVisitor.visitBeanDefinition(BeanDefinitionVisitor.java:82)     在org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:208)     ...省略了13个常见帧

资源/ batch-db2.properties

spring.jpa.hibernate.dialect: org.hibernate.dialect.DB2Dialect
spring.jpa.show-sql: false
spring.jpa.generate-ddl: false

database.minion.url=jdbc:db2://***
database.minion.username=***
database.minion.password=***
database.minion.driver-class-name=com.ibm.db2.jcc.DB2Driver

资源/ application.properties

server.port=8091
-DENVIRONMENT=db2

主要课程

@ComponentScan(basePackageClasses={ PersistenceConfig.class })
@SpringBootApplication(exclude = {HypermediaAutoConfiguration.class, MultipartAutoConfiguration.class})
@EnableBatchAdmin
public class MinionBatchApplication {

    public static void main(String[] args) {
        SpringApplication.run(MinionBatchApplication.class, args);
    }
}

数据源配置

@Configuration
public class PersistenceConfig {

  @Bean
    @ConfigurationProperties(prefix = "database.minion")
    public DataSource minionDataSource() {
        return DataSourceBuilder
            .create()
            .build();
    }}

1 个答案:

答案 0 :(得分:3)

当您使用spring批量管理员时,重要的是覆盖spring batch admin提供的文件。(请查看配置设置的图像) 然后你的属性文件应该是这样的 enter image description here

 # Placeholders batch.*
#    for MySQL:
batch.jdbc.driver=com.mysql.jdbc.Driver
batch.jdbc.url=jdbc:mysql://localhost:3306/xxxx
batch.jdbc.user=root
batch.jdbc.password=root
batch.jdbc.testWhileIdle=true
batch.jdbc.validationQuery=SELECT 1
batch.schema.script=classpath:/org/springframework/batch/core/schema-mysql.sql
batch.drop.script=classpath*:/org/springframework/batch/core/schema-drop-mysql.sql
batch.business.schema.script=classpath:business-schema-mysql.sql
batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.MySQLMaxValueIncrementer

# Non-platform dependent settings that you might like to change
 batch.data.source.init=false

我认为在你的情况下“驱动程序类”的属性名称是不同的。