2017-03-17 70 views
0

我试图将Spring批处理与Spring批处理管理器集成。但我得到这个错误Could not resolve placeholder 'batch.jdbc.driver' in string value "${batch.jdbc.driver}"请help.Thanks。

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) 在org.springframework.beans.factory.config.PropertyPlaceholderConfigurer $ PlaceholderResolvingStringValueResolver.resolveStringValue(PropertyPlaceholderConfigurer.java:258) at 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个共同帧省略

resources/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(); 
    }} 
+0

启动服务器时,您能够看到控制台中的属性? – VelNaga

+0

我从来没有使用弹簧引导批处理,但我有弹簧引导应用程序的经验..而不是“-DENVIRONMENT = db2”设置“-DENVIRONMENT = batch-db2” – VelNaga

+0

我不确定你的application.properties文件将被采摘在batch-db2.properties之前的spring之前。一种确定的方法是在src/main/resources中添加一个名为“bootstrap.yml”的文件。 bootstrap.yml将在任何应用程序属性file.add之前加载文件中的内容,如下所示:ENVIRONMENT:db2 – htulsiani

回答

3

当您使用的弹簧BATC h联系覆盖的春天批次管理员提供的文件是很重要的。(请找到配置设置的图像) ,然后你的属性文件应该是这样的 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 

我觉得你的情况“的驱动程序类“属性名称是不同的。

+0

不会'batch.drop.script = classpath *:/ org/springframework/batch/core/schema-drop-mysql.sql ,, drop existing tables',我正在使用现有的数据库,我不想在这种情况下删除表 –

+0

删除“batch.drop。脚本“属性。你想要覆盖哪些属性提到这些,休息你删除它。 –

+1

它的工作,显然是“batch.data.source.init = false”,防止它丢弃表:) –