All Downloads are FREE. Search and download functionalities are using the official Maven repository.

templates.service.DatasourceConfig.ftl Maven / Gradle / Ivy

There is a newer version: 2.0.4
Show newest version
package ${packageName}.service.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.yes.tools.datasource.annotation.IDynamicDataSourceProvider;
import org.yes.tools.datasource.provider.DynamicDataSource;

import javax.sql.DataSource;

/**
 * @author Co.
 * @name DatasourceConfig
 * @date 2023/1/7 18:55
 */
@Configuration
public class DatasourceConfig {
    @Autowired
    IDynamicDataSourceProvider dynamicDataSourceProvider;

//    @Primary
//    @Bean
//    public PlatformTransactionManager transactionManager(@Qualifier("dataSource") DataSource dataSource) {
//        return new DataSourceTransactionManager(new SeataDataSourceProxy(dataSource));
//    }

//    @Bean
//    @ConfigurationProperties(prefix = "spring.datasource")
//    public DynamicDataSource dynamicDataSource() {
//        return new DynamicDataSource(dynamicDataSourceProvider);
//    }

    @Primary
    @Bean("dataSource")
    public DataSource dataSource() {
        DynamicDataSource dynamicDataSource = new DynamicDataSource(dynamicDataSourceProvider);
        return dynamicDataSource;
    }

//    @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
//    @Bean
//    @ConditionalOnProperty(prefix = "spring.datasource.dynamic", name = "seata", havingValue = "true", matchIfMissing = true)
//    public Advisor dynamicTransactionAdvisor() {
//        DynamicTransactionInterceptor interceptor = new DynamicTransactionInterceptor();
//        return new DynamicDataSourceAnnotationAdvisor(interceptor, GlobalTransactional.class);
//    }

//    @Bean(name = "dataSourceTransactionManager")
//    public DataSourceTransactionManager dataSourceTransactionManager(DataSource dataSource) {
//        DynamicDataSource dynamicDataSource = new DynamicDataSource(dynamicDataSourceProvider);
//        DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager();
//        dataSourceTransactionManager.setDataSource(dataSource);
//        return dataSourceTransactionManager;
//    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy