My application.properties file.

    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=

My Jpa Config file

        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;
    }


}

My router file

@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}");


    }
}

I cannot understand why I get this error. I added in my router class all entitymanager with autowired annotation and it is initialized. I checked it in the debug mode. But why my apache camel couldn't find it in his registry?

Some decision suggest to describe connection config in the persistence.xml file. But I don't want use this file. I want use application.properties for this goals.

1

There are 1 answers

0
Suleyman Batyrov On

I decided my problem.

You must begin you route with name of the JpaComponent.

    from("timer://readDataFromOldDealer?period=60000").
           to("oldDealerJpaComponent:com.flytech.camelrouter.entity.olddealer.Network?" +