Size: a a a

Spring Framework and more

2019 November 26

T

Tom in Spring Framework and more
Илья
I mean it)
Alright, so is there something that you can fix of that might fix that ?
источник

И

Илья in Spring Framework and more
источник

И

Илья in Spring Framework and more
Tom
Alright, so is there something that you can fix of that might fix that ?
?
источник

T

Tom in Spring Framework and more
yes saw that and this is pretty much what I did
источник

И

Илья in Spring Framework and more
Tom
yes saw that and this is pretty much what I did
But I get sight of difference in using @Qualifier and injections in config classes
источник

И

Илья in Spring Framework and more
Tom
yes saw that and this is pretty much what I did
I think you need to inject dataSource class in LocalContainerEntityManagerFactoryBean with @Qualifier annotation. Like this https://github.com/jahe/spring-boot-multiple-datasources/blob/master/src/main/java/com/foobar/BarDbConfig.java.
This is more concise and correct.
источник

T

Tom in Spring Framework and more
ok I will try it, thanks#
источник

SD

Sergey Dyakin in Spring Framework and more
Tom
Alright, so is there something that you can fix of that might fix that ?
источник

SD

Sergey Dyakin in Spring Framework and more
I think it’s more flex solution
источник

SD

Sergey Dyakin in Spring Framework and more
I use this solution in my project
источник

ВС

Владислав Славетный in Spring Framework and more
yo, guys. Who can give me awesome youtube spring guide for beginners?
источник

T

Tom in Spring Framework and more
Just tried it, gave me same error 🙁
источник

T

Tom in Spring Framework and more
Thanks I will look through it!
источник

И

Илья in Spring Framework and more
Sergey Dyakin
I use this solution in my project
But You can use profiling insted of your solution. I think that profiling more convenient
источник

И

Илья in Spring Framework and more
Tom
Just tried it, gave me same error 🙁
Could you share your code ?
источник

T

Tom in Spring Framework and more
Илья
Could you share your code ?
Sure
источник

T

Tom in Spring Framework and more
@Configuration
@EnableJpaRepositories(
       basePackages = "REPOPACKAGE.FIRST",
       entityManagerFactoryRef = "EntityManagerFactory",
       transactionManagerRef= "TransactionManager"
)
public class FirstDataSourceConfig {
   
   public FirstDataSourceConfig() {
       super();
   }

   @Value("${spring.first-datasource.url}")
   private String url;

   @Value("${spring.first-datasource.username}")
   private String username;

   @Value("${spring.first-datasource.password}")
   private String pw;

   @Value("${spring.first-datasource.driver-class-name}")
   private String driver;


   @Bean
   @Primary
   @ConfigurationProperties("spring.first-datasource")
   public DataSourceProperties firstDataSourceProperties() {
       return new DataSourceProperties();
   }

   @Bean("DataSource")
   @Primary
   public DataSource firstDataSource() {

       DriverManagerDataSource dataSource
               = new DriverManagerDataSource();
       dataSource.setDriverClassName(
               driver);
       dataSource.setUrl(url);
       dataSource.setUsername(username);
       dataSource.setPassword(pw);

       return dataSource;
   }

   @Primary
   @Bean("EntityManagerFactory")
   public LocalContainerEntityManagerFactoryBean firstEntityManagerFactory( @Qualifier("DataSource") DataSource dataSource) {
       LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
       em.setDataSource(dataSource);
       em.setPersistenceUnitName("first");
       em.setPackagesToScan("DOMAINCLASSES.First");
       HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
       vendorAdapter.setDatabasePlatform("org.hibernate.dialect.MySQLDialect");
       em.setJpaVendorAdapter(vendorAdapter);

       return em;
   }

   @Primary
   @Bean("TransactionManager")
   public PlatformTransactionManager firstTransactionManager(  @Qualifier("EntityManagerFactory") EntityManagerFactory barEntityManagerFactory) {
       return new JpaTransactionManager(barEntityManagerFactory);
   }

}
источник

T

Tom in Spring Framework and more
let me know if you need anything else
источник

И

Илья in Spring Framework and more
What about second DataSourceConfig?
источник

T

Tom in Spring Framework and more
Илья
What about second DataSourceConfig?
the scond one is pretty much the same as the first one just withput the primary annotation and different domain and persistence packages
источник