phdbutbachelor commented on issue #18178:
URL:
https://github.com/apache/shardingsphere/issues/18178#issuecomment-1148164639
you can inject a ShardingSphereDataSource bean into a
LocalSesstionFactoryBean, then a PlatformTransactionManager:
-----------------------------------------------------------------------------------------------------------------------------------
@Bean
public DataSource mainShardingSphereDataSource() throws IOException,
SQLException {
File _yaml = ResourceUtils.getFile("classpath:shardingsphere.yml");
return YamlShardingSphereDataSourceFactory.createDataSource(_yaml);
}
@Bean
public LocalSessionFactoryBean mainShardingSphereSessionFactory(@Value(value
= "${spring.datasource.main.dialect}") String dialect, @Qualifier(value =
"mainShardingSphereDataSource") DataSource dataSource) {
LocalSessionFactoryBean _localSessionFactoryBean = new
LocalSessionFactoryBean();
_localSessionFactoryBean.setDataSource(dataSource);
_localSessionFactoryBean.setPackagesToScan("gmcc.sparrow.model.set");
Properties _properties = new Properties();
_properties.setProperty("hibernate.dialect", dialect); // 设置方言
_localSessionFactoryBean.setHibernateProperties(_properties);
return _localSessionFactoryBean;
}
@Bean
public PlatformTransactionManager
mainShardingSphereTransactionManager(@Qualifier(value =
"mainShardingSphereSessionFactory") EntityManagerFactory entityManagerFactory) {
return new JpaTransactionManager(entityManagerFactory);
}
-----------------------------------------------------------------------------------------------------------------------------------
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]