Bom dia, consegui desta forma:
DataSource 1:
@Bean(name = "em_Local")
@Primary
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(createH2DataSource());
em.setPackagesToScan(new String[] { "com.teste.*"});
em.setPersistenceUnitName("LocalPU");
JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
em.setJpaProperties(additionalProperties());
return em;
}
@Bean(name = "tm_Local")
@Primary
public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(emf);
return transactionManager;
}
private Properties additionalProperties() {
Properties properties = new Properties();
properties.setProperty("hibernate.hbm2ddl.auto", "update");
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
properties.setProperty("hibernate.connection.driver_class", "org.h2.Driver");
return properties;
}
private DataSource createH2DataSource() {
JndiDataSourceLookup cxt = new JndiDataSourceLookup();
DataSource dataSource = cxt.getDataSource("java:/comp/env/LOCALDS");
return dataSource;
}
DataSource 2:
@Bean
@Primary
JdbcTemplate jdbcTemplate() {
JndiDataSourceLookup cxt = new JndiDataSourceLookup();
DataSource dataSource = cxt.getDataSource("java:/comp/env/TESTEDS2");
return new JdbcTemplate(dataSource);
}