Search in sources :

Example 71 with Primary

use of org.springframework.context.annotation.Primary in project tutorials by eugenp.

the class SessionConfig method connectionFactory.

@Bean
@Primary
public JedisConnectionFactory connectionFactory() {
    JedisConnectionFactory factory = new JedisConnectionFactory();
    factory.setHostName(properties.getProperty("spring.redis.host", "localhost"));
    factory.setPort(properties.getProperty("spring.redis.port", Integer.TYPE, 6379));
    factory.afterPropertiesSet();
    factory.setUsePool(true);
    return factory;
}
Also used : JedisConnectionFactory(org.springframework.data.redis.connection.jedis.JedisConnectionFactory) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean)

Example 72 with Primary

use of org.springframework.context.annotation.Primary in project flybiner-sso by youyouxi.

the class DruidConfig method druidDataSource.

/**
 * @deprecated  @Bean(destroyMethod = "close", initMethod = "init")
 * 解决 druid 页面出错 (*) property for user to setup
 */
@Bean(destroyMethod = "close", initMethod = "init")
@Primary
public DataSource druidDataSource() {
    DruidDataSource datasource = new DruidDataSource();
    datasource.setUrl(this.dbUrl);
    datasource.setUsername(username);
    datasource.setPassword(password);
    datasource.setDriverClassName(driverClassName);
    datasource.setInitialSize(initialSize);
    datasource.setMinIdle(minIdle);
    datasource.setMaxActive(maxActive);
    datasource.setMaxWait(maxWait);
    datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
    datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
    datasource.setValidationQuery(validationQuery);
    datasource.setTestWhileIdle(testWhileIdle);
    datasource.setTestOnBorrow(testOnBorrow);
    datasource.setTestOnReturn(testOnReturn);
    datasource.setPoolPreparedStatements(poolPreparedStatements);
    try {
        datasource.setFilters(filters);
    } catch (SQLException e) {
        logger.error("druid configuration initialization filter", e);
    }
    return datasource;
}
Also used : SQLException(java.sql.SQLException) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) Primary(org.springframework.context.annotation.Primary) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 73 with Primary

use of org.springframework.context.annotation.Primary in project neweagle-api by apgzs.

the class DruidConfiguration method dataSource.

@Bean
@Primary
public DataSource dataSource() {
    DruidDataSource datasource = new DruidDataSource();
    datasource.setUrl(this.dbUrl);
    datasource.setUsername(username);
    datasource.setPassword(password);
    datasource.setDriverClassName(driverClassName);
    // configuration
    if (initialSize != null) {
        datasource.setInitialSize(initialSize);
    }
    if (minIdle != null) {
        datasource.setMinIdle(minIdle);
    }
    if (maxActive != null) {
        datasource.setMaxActive(maxActive);
    }
    if (maxWait != null) {
        datasource.setMaxWait(maxWait);
    }
    if (timeBetweenEvictionRunsMillis != null) {
        datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
    }
    if (minEvictableIdleTimeMillis != null) {
        datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
    }
    if (validationQuery != null) {
        datasource.setValidationQuery(validationQuery);
    }
    if (testWhileIdle != null) {
        datasource.setTestWhileIdle(testWhileIdle);
    }
    if (testOnBorrow != null) {
        datasource.setTestOnBorrow(testOnBorrow);
    }
    if (testOnReturn != null) {
        datasource.setTestOnReturn(testOnReturn);
    }
    if (poolPreparedStatements != null) {
        datasource.setPoolPreparedStatements(poolPreparedStatements);
    }
    if (maxPoolPreparedStatementPerConnectionSize != null) {
        datasource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
    }
    if (connectionProperties != null) {
        datasource.setConnectionProperties(connectionProperties);
    }
    List<Filter> filters = new ArrayList<>();
    filters.add(statFilter());
    filters.add(wallFilter());
    datasource.setProxyFilters(filters);
    return datasource;
}
Also used : WallFilter(com.alibaba.druid.wall.WallFilter) WebStatFilter(com.alibaba.druid.support.http.WebStatFilter) Filter(com.alibaba.druid.filter.Filter) StatFilter(com.alibaba.druid.filter.stat.StatFilter) ArrayList(java.util.ArrayList) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) Primary(org.springframework.context.annotation.Primary) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 74 with Primary

use of org.springframework.context.annotation.Primary in project tutorials-java by Artister.

the class MasterDataSourceConfig method masterDataSource.

@Bean(name = "masterDataSource")
@Primary
public DataSource masterDataSource() {
    DruidDataSource dataSource = new DruidDataSource();
    dataSource.setDriverClassName(driverClass);
    dataSource.setUrl(url);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    return dataSource;
}
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 75 with Primary

use of org.springframework.context.annotation.Primary in project lzl_workspace by hpulzl.

the class MasterDataSourceConfig method masterSqlSessionFactory.

@Bean(name = "masterSqlSessionFactory")
@Primary
public SqlSessionFactory masterSqlSessionFactory() {
    final SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();
    sessionFactoryBean.setDataSource(masterDruidDataSource());
    try {
        sessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(MASTER_MAPPER_LOCAL));
        return sessionFactoryBean.getObject();
    } catch (Exception e) {
        logger.error("配置主库的SqlSessionFactory失败,error:{}", e.getMessage());
        throw new RuntimeException(e.getMessage());
    }
}
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)93 Bean (org.springframework.context.annotation.Bean)90 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)15 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