Наше приложение использует Oracle 11.2 в качестве базы данных. Поскольку не хотел смешивать таблицы «метаданных пружинных» с обычными таблицами приложения, он создал новую схему. Но, пытаясь настроить оба отдельных источника данных, продолжайте получать ошибку ниже:
//configuration first datasource
@Configuration
@EnableBatchProcessing
public class BatchConfig{
private static final Logger logger = LoggerFactory.getLogger(ReutersMarketDataReadConfig.class);
..
@Bean
@ConfigurationProperties(prefix = "spring.batch.datasource")
public DataSource getBatchDataSource() {
return DataSourceBuilder.create().build();
}
....
}
//second data source
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
entityManagerFactoryRef = "appEntityManagerFactory",
transactionManagerRef = "appTransactionManager",
basePackages = {"com.xyz.abc.repository" }
)
public class ApplicationDBConfig {
@Primary
@Bean(name = "appDataSource")
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
@Primary
@Bean(name = "appEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder,
@Qualifier("appDataSource") DataSource dataSource) {
return builder.dataSource(dataSource).packages("com.xyz.abc.model").persistenceUnit("app").build();
}
@Primary
@Bean(name = "appTransactionManager")
public PlatformTransactionManager transactionManager(
@Qualifier("appEntityManagerFactory") EntityManagerFactory entityManagerFactory) {
return new JpaTransactionManager(entityManagerFactory);
}
}
Ошибка:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
[30m2019-04-02 14:56:16,706[0;39m [1;31mERROR[0;39m [[34mrestartedMain[0;39m] [33morg.springframework.boot.SpringApplication[0;39m: Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jobInvokerController': Unsatisfied dependency expressed through field 'processLiborFeedJob'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'processLiborFeedJob' defined in class path resource [com/db/sts/marketdata/batch/config/ReutersMarketDataReadConfig.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'taskBatchExecutionListener' defined in class path resource [org/springframework/cloud/task/batch/configuration/TaskBatchAutoConfiguration$TaskBatchExecutionListenerAutoconfiguration.class]: Unsatisfied dependency expressed through method 'taskBatchExecutionListener' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cloud.task.configuration.SimpleTaskAutoConfiguration': Invocation of init method failed; nested exception is java.lang.IllegalStateException: To use the default TaskConfigurer the context must contain no more than one DataSource, found 2
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:596)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90)