Search in sources :

Example 16 with Primary

use of org.springframework.context.annotation.Primary in project springBoot-learn-demo by nbfujx.

the class DruidOneConfig method DataSourceTransactionManagerOne.

// 数据源事务管理器
@Primary
@Bean
public DataSourceTransactionManager DataSourceTransactionManagerOne() {
    DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager();
    dataSourceTransactionManager.setDataSource(dataSourceOne());
    return dataSourceTransactionManager;
}
Also used : DataSourceTransactionManager(org.springframework.jdbc.datasource.DataSourceTransactionManager) Primary(org.springframework.context.annotation.Primary) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 17 with Primary

use of org.springframework.context.annotation.Primary in project Spring-Family by Sierou-Java.

the class MasterDataSourceConfig method masterDataSource.

@Bean(name = "masterDataSource")
@Primary
@ConfigurationProperties(prefix = "master.datasource")
public DataSource masterDataSource() {
    DruidDataSource dataSource = new DruidDataSource();
    dataSource.setDriverClassName(driverClass);
    dataSource.setUrl(url);
    dataSource.setUsername(user);
    // System.out.println(SecurityAES.decrypt(password, "123"));
    // dataSource.setPassword(SecurityAES.decrypt(password, "123"));
    dataSource.setPassword(password);
    dataSource.setMaxActive(maxActive);
    dataSource.setInitialSize(initialSize);
    dataSource.setMinIdle(minIdle);
    // dataSource.setConnectionProperties("master.datasource.password=" + password);
    return dataSource;
}
Also used : DruidDataSource(com.alibaba.druid.pool.DruidDataSource) Primary(org.springframework.context.annotation.Primary) ConfigurationProperties(org.springframework.boot.context.properties.ConfigurationProperties) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 18 with Primary

use of org.springframework.context.annotation.Primary in project Spring-Family by Sierou-Java.

the class MasterDataSourceConfig method masterSqlSessionFactory.

@Bean(name = "masterSqlSessionFactory")
@Primary
public SqlSessionFactory masterSqlSessionFactory(@Qualifier("masterDataSource") DataSource masterDataSource) throws Exception {
    final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
    sessionFactory.setDataSource(masterDataSource);
    sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(MasterDataSourceConfig.MAPPER_LOCATION));
    return sessionFactory.getObject();
}
Also used : SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) Primary(org.springframework.context.annotation.Primary) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 19 with Primary

use of org.springframework.context.annotation.Primary in project spring-boot-quick by vector4wang.

the class DataSourcePrimaryConfig method testDataSource.

@Bean(name = "primaryDataSource", initMethod = "init", destroyMethod = "close")
@Primary
public DataSource testDataSource() throws SQLException {
    DruidDataSource druidDataSource = new DruidDataSource();
    druidDataSource.setDriverClassName(druidConfigPrimaryProperties.getDriverClassName());
    druidDataSource.setUrl(druidConfigPrimaryProperties.getUrl());
    druidDataSource.setUsername(druidConfigPrimaryProperties.getUsername());
    druidDataSource.setPassword(druidConfigPrimaryProperties.getPassword());
    druidDataSource.setInitialSize(druidConfigPrimaryProperties.getMinIdle());
    druidDataSource.setMinIdle(druidConfigPrimaryProperties.getMinIdle());
    druidDataSource.setMaxActive(druidConfigPrimaryProperties.getMaxActive());
    druidDataSource.setMaxWait(druidConfigPrimaryProperties.getMaxWait());
    druidDataSource.setTimeBetweenEvictionRunsMillis(druidConfigPrimaryProperties.getTimeBetweenEvictionRunsMillis());
    druidDataSource.setMinEvictableIdleTimeMillis(druidConfigPrimaryProperties.getMinEvictableIdleTimeMillis());
    druidDataSource.setValidationQuery(druidConfigPrimaryProperties.getValidationQuery());
    druidDataSource.setTestWhileIdle(druidConfigPrimaryProperties.getTestWhileIdle());
    druidDataSource.setTestOnBorrow(druidConfigPrimaryProperties.getTestOnBorrow());
    druidDataSource.setTestOnReturn(druidConfigPrimaryProperties.getTestOnReturn());
    druidDataSource.setPoolPreparedStatements(druidConfigPrimaryProperties.getPoolPreparedStatements());
    druidDataSource.setMaxPoolPreparedStatementPerConnectionSize(druidConfigPrimaryProperties.getMaxPoolPreparedStatementPerConnectionSize());
    druidDataSource.setFilters(druidConfigPrimaryProperties.getFilters());
    return druidDataSource;
}
Also used : DruidDataSource(com.alibaba.druid.pool.DruidDataSource) Primary(org.springframework.context.annotation.Primary) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 20 with Primary

use of org.springframework.context.annotation.Primary in project spring-boot-quick by vector4wang.

the class DataSourcePrimaryConfig method testSqlSessionFactory.

@Bean(name = "primarySqlSessionFactory")
@Primary
public SqlSessionFactory testSqlSessionFactory(@Qualifier("primaryDataSource") DataSource dataSource) throws Exception {
    SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
    bean.setDataSource(dataSource);
    bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/primary/*.xml"));
    return bean.getObject();
}
Also used : SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) Primary(org.springframework.context.annotation.Primary) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

Primary (org.springframework.context.annotation.Primary)87 Bean (org.springframework.context.annotation.Bean)84 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)14 SqlSessionFactoryBean (org.mybatis.spring.SqlSessionFactoryBean)13 SQLException (java.sql.SQLException)10 LocalContainerEntityManagerFactoryBean (org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)10 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 JpaTransactionManager (org.springframework.orm.jpa.JpaTransactionManager)7 ServletRegistrationBean (org.springframework.boot.web.servlet.ServletRegistrationBean)6 DefaultTokenServices (org.springframework.security.oauth2.provider.token.DefaultTokenServices)6 JavaTimeModule (com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)4 ConfigurationProperties (org.springframework.boot.context.properties.ConfigurationProperties)4 JodaModule (com.fasterxml.jackson.datatype.joda.JodaModule)3 LocalDateSerializer (com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer)3 LocalDateTimeSerializer (com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer)3 LocalTimeSerializer (com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer)3 XmAuthenticationContext (com.icthh.xm.commons.security.XmAuthenticationContext)3 XmAuthenticationContextHolder (com.icthh.xm.commons.security.XmAuthenticationContextHolder)3 FilterRegistrationBean (org.springframework.boot.web.servlet.FilterRegistrationBean)3