我需要创建一个在Spring Boot创建连接之前执行的bean,所以我有2个@Config来创建我的dbs
<body>
<h2>Choose Your Side</h2>
<div class="rebels">
<div onclick="chooseSide()">
<img id="logo" src="../img/rebels.jpg" alt="Rebels" height="320" width="380">
</div>
</div>
<div class="empire">
<div onclick="chooseSide()">
<img id="logo" src="../img/empire.jpg" alt="Empire" height="300" width="300">
</div>
</div>
function soldier(side, weapon, sidearm) {
this.side = function chooseSide() {
//code here
}
}
和
@Configuration
@EnableJpaRepositories(entityManagerFactoryRef = "dbregistroEntityManagerFactory",basePackages = {"br.com.lumera.repositories.registro"})
@EnableTransactionManagement
public class DbRegistroConfig {
@Bean(name = "dbRegistroDataSource")
@ConfigurationProperties(prefix = "datasource.dbregistro")
public DataSource secondaryDataSource(){
return DataSourceBuilder.create().build();
}
@Bean(name = "dbregistroEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean dbregistroEntityManagerFactory(
EntityManagerFactoryBuilder builder, @Qualifier("dbRegistroDataSource") DataSource dbRegistroDataSource) {
return builder
.dataSource(dbRegistroDataSource)
.packages("br.com.lumera.entity.registro")
.persistenceUnit("dbregistro")
.build();
}
@Bean(name = "dbregistroTransactionManager")
public JpaTransactionManager dbRegistroTransactionManager(@Qualifier("dbregistroEntityManagerFactory") final EntityManagerFactory factory)
{
return new JpaTransactionManager(factory);
}
}
然后我用autoconfigurate创建我的类:
@Configuration
@EnableJpaRepositories(entityManagerFactoryRef = "entityManagerFactory", basePackages = {"br.com.lumera.repositories.dnaso"})
@EnableTransactionManagement
public class DbDnasoConfig {
@Bean(name = "dataSource")
@Primary
@ConfigurationProperties(prefix = "datasource.dnaso")
public DataSource primaryDataSource() {
return DataSourceBuilder.create().build();
}
@Bean(name = "entityManagerFactory")
@Primary
public LocalContainerEntityManagerFactoryBean dbdnasoEntityManagerFactory(
EntityManagerFactoryBuilder builder, @Qualifier("dataSource") DataSource dataSource) {
return builder
.dataSource(dataSource)
.packages("br.com.lumera.entity.dnaso")
.persistenceUnit("dbdnaso")
.build();
}
@Bean(name = "transactionManager")
@Primary
public JpaTransactionManager dbRegistroTransactionManager(@Qualifier("entityManagerFactory") final EntityManagerFactory factory)
{
return new JpaTransactionManager(factory);
}
}
但他在我的DbRegistroConfig和DbDnasoConfig之后执行任何人都可以帮助我吗?