Search in sources :

Example 81 with Primary

use of org.springframework.context.annotation.Primary in project pinpoint by naver.

the class CacheConfiguration method cacheManager.

@Bean
@Primary
public CacheManager cacheManager() {
    CaffeineCacheManager cacheManager = new CaffeineCacheManager();
    cacheManager.setCaffeine(Caffeine.newBuilder().expireAfterWrite(600, TimeUnit.SECONDS).initialCapacity(200).maximumSize(1000));
    return cacheManager;
}
Also used : CaffeineCacheManager(org.springframework.cache.caffeine.CaffeineCacheManager) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean)

Example 82 with Primary

use of org.springframework.context.annotation.Primary in project micro-service by Lovnx.

the class DruidDataSourceConfig method druidDataSource.

@Bean
@Primary
public DataSource druidDataSource() {
    DruidDataSource datasource = new DruidDataSource();
    datasource.setUrl(dataSourceProperties.getUrl());
    datasource.setUsername(dataSourceProperties.getUsername());
    datasource.setPassword(dataSourceProperties.getPassword());
    datasource.setDriverClassName(dataSourceProperties.getDriverClassName());
    datasource.setInitialSize(dataSourceProperties.getInitialSize());
    datasource.setMinIdle(dataSourceProperties.getMinIdle());
    datasource.setMaxActive(dataSourceProperties.getMaxActive());
    datasource.setMaxWait(dataSourceProperties.getMaxWait());
    datasource.setTimeBetweenEvictionRunsMillis(dataSourceProperties.getTimeBetweenEvictionRunsMillis());
    datasource.setMinEvictableIdleTimeMillis(dataSourceProperties.getMinEvictableIdleTimeMillis());
    datasource.setValidationQuery(dataSourceProperties.getValidationQuery());
    datasource.setTestWhileIdle(dataSourceProperties.isTestWhileIdle());
    datasource.setTestOnBorrow(dataSourceProperties.isTestOnBorrow());
    datasource.setTestOnReturn(dataSourceProperties.isTestOnReturn());
    datasource.setPoolPreparedStatements(dataSourceProperties.isPoolPreparedStatements());
    try {
        datasource.setFilters(dataSourceProperties.getFilters());
    } catch (SQLException e) {
        logger.error("Druid configuration initialization filter error.", e);
    }
    return datasource;
}
Also used : SQLException(java.sql.SQLException) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean)

Example 83 with Primary

use of org.springframework.context.annotation.Primary in project new-cloud by xie-summer.

the class DruidDbConfig method dataSource.

/**
 * @return 声明其为Bean实例
 * 在同样的DataSource中,首先使用被标注的DataSource
 */
@Bean
@Primary
public DataSource dataSource() {
    DruidDataSource datasource = new DruidDataSource();
    datasource.setUrl(masterUrl);
    datasource.setUsername(username);
    datasource.setPassword(password);
    datasource.setDriverClassName(driverClassName);
    // configuration
    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);
    datasource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
    try {
        datasource.setFilters(filters);
    } catch (SQLException e) {
        logger.error("druid configuration initialization filter", e);
    }
    datasource.setConnectionProperties(connectionProperties);
    return datasource;
}
Also used : SQLException(java.sql.SQLException) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean)

Example 84 with Primary

use of org.springframework.context.annotation.Primary in project new-cloud by xie-summer.

the class DruidDbConfig method dataSource.

/**
 * @return 声明其为Bean实例
 * 在同样的DataSource中,首先使用被标注的DataSource
 */
@Bean
@Primary
public DataSource dataSource() {
    DruidDataSource datasource = new DruidDataSource();
    datasource.setUrl(dbUrl);
    datasource.setUsername(username);
    datasource.setPassword(password);
    datasource.setDriverClassName(driverClassName);
    // configuration
    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);
    datasource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
    try {
        datasource.setFilters(filters);
    } catch (SQLException e) {
        logger.error("druid configuration initialization filter", e);
    }
    datasource.setConnectionProperties(connectionProperties);
    return datasource;
}
Also used : SQLException(java.sql.SQLException) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean)

Example 85 with Primary

use of org.springframework.context.annotation.Primary in project new-cloud by xie-summer.

the class DruidDbConfig method dataSource.

/**
 * @return 声明其为Bean实例
 * 在同样的DataSource中,首先使用被标注的DataSource
 */
@Bean
@Primary
public DataSource dataSource() {
    DruidDataSource datasource = new DruidDataSource();
    datasource.setUrl(dbUrl);
    datasource.setUsername(username);
    datasource.setPassword(password);
    datasource.setDriverClassName(driverClassName);
    // configuration
    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);
    datasource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
    try {
        datasource.setFilters(filters);
    } catch (SQLException e) {
        logger.error("druid configuration initialization filter", e);
    }
    datasource.setConnectionProperties(connectionProperties);
    return datasource;
}
Also used : SQLException(java.sql.SQLException) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) Primary(org.springframework.context.annotation.Primary) 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