我的application.properties文件。
spring.datasource.olddealer.driver-class-name=org.mariadb.jdbc.Driver
spring.datasource.olddealer.jdbcUrl=jdbc:mariadb://10.0.0.222/dealer_cabinet
spring.datasource.olddealer.url=jdbc:mariadb://10.0.0.222/dealer_cabinet
spring.datasource.olddealer.username=dealer_cabinet
spring.datasource.olddealer.password=
spring.datasource.newdealer.driver-class-name=org.mariadb.jdbc.Driver
spring.datasource.newdealer.jdbcUrl=jdbc:mariadb://10.0.0.222/dealer
spring.datasource.newdealer.url=jdbc:mariadb://10.0.0.222/dealer
spring.datasource.newdealer.username=dealer_cabinet
spring.datasource.newdealer.password=
我的Jpa配置文件
entityManagerFactoryRef = OldDealerConfiguration.ENTITY_MANAGER_FACTORY,
transactionManagerRef = OldDealerConfiguration.TRANSACTION_MANAGER,
basePackages = OldDealerConfiguration.JPA_REPOSITORY_PACKAGE
)
@Configuration
public class OldDealerConfiguration {
public static final String ENTITY_MANAGER_FACTORY = "oldDealerEntityManagerFactory";
public static final String TRANSACTION_MANAGER = "oldDealerTransactionManager";
public static final String JPA_REPOSITORY_PACKAGE = "com.flytech.camelrouter.repository.olddealer";
@Bean(name = "oldDealerProperties")
@Primary
@ConfigurationProperties("spring.datasource.olddealer")
DataSourceProperties oldDealerDataSourceProperties(){
return new DataSourceProperties();
}
@Bean(name = "oldDealerDataSource")
@Primary
@ConfigurationProperties(prefix="spring.datasource.olddealer")
public DataSource oldDealerDataSource(@Qualifier("oldDealerProperties") DataSourceProperties dataSourceProperties) {
return dataSourceProperties.initializeDataSourceBuilder().build();
}
@Bean(name = ENTITY_MANAGER_FACTORY)
@org.apache.camel.language.bean.Bean(ref = ENTITY_MANAGER_FACTORY)
public LocalContainerEntityManagerFactoryBean oldDealerEntityManagerFactoryBean(
@Qualifier("oldDealerDataSource") DataSource dataSource){
LocalContainerEntityManagerFactoryBean emfb = new LocalContainerEntityManagerFactoryBean();
emfb.setPersistenceUnitName("oldDealer");
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
vendorAdapter.setDatabasePlatform("org.hibernate.dialect.MariaDBDialect");
emfb.setJpaVendorAdapter(vendorAdapter);
emfb.setDataSource(dataSource);
emfb.setPackagesToScan("com.flytech.camelrouter.entity.olddealer");
emfb.afterPropertiesSet();
return emfb;
}
@Bean(name = TRANSACTION_MANAGER)
public PlatformTransactionManager oldDealerTransactionManager(
@Qualifier(ENTITY_MANAGER_FACTORY) EntityManagerFactory entityManagerFactory){
JpaTransactionManager jpaTransactionManager = new JpaTransactionManager();
jpaTransactionManager.setEntityManagerFactory(entityManagerFactory);
return jpaTransactionManager;
}
@Bean("oldDealerJpaComponent")
@org.apache.camel.language.bean.Bean(ref = "oldDealerJpaComponent")
public JpaComponent oldDealerJpaComponent(
@Qualifier(OldDealerConfiguration.ENTITY_MANAGER_FACTORY)EntityManagerFactory entityManagerFactory,
CamelContext camelContext){
JpaComponent jpaComponent = new JpaComponent();
jpaComponent.setEntityManagerFactory(entityManagerFactory);
jpaComponent.setCamelContext(camelContext);
return jpaComponent;
}
}
路由器文件
@Component
public class SecondTestRouter extends RouteBuilder {
@Autowired
@Qualifier("oldDealerJpaComponent")
JpaComponent jpaComponent;
@Autowired
@PersistenceContext(unitName = "oldDealer")
EntityManager oldEntityManager;
@Autowired
@PersistenceContext(unitName = "newDealer")
EntityManager newEntityManager;
@Override
public void configure() throws Exception {
from("timer://readDataFromOldDealer?period=60000").
to("jpa:com.flytech.camelrouter.entity.olddealer.Network?" +
"resultClass=com.flytech.camelrouter.entity.olddealer.Network&" +
"persistenceUnit=oldDealer&nativeQuery=SELECT n.dealer, n.network, n.location, n.benefit, n.prefix, n.cid, n.locality_id, u.full_name, u.email, u.phone FROM networks n INNER join user u on n.dealer = u.username;").
log("${body.dealer}");
}
}
我不明白为什么我会犯这个错误。我在我的路由器类中添加了所有带有autowired注解的entitymanager,它被初始化了。我在调试模式下检查过了。但为什么我的Apache Camel 在他的注册表里找不到呢?
一些决策建议在persistence.xml文件中描述连接配置。但我不想用这个文件。我想使用application.properties来实现这个目标。
1条答案
按热度按时间yqyhoc1h1#
我决定了我的问题。
必须以JpaComponent的名称开始布线。