Search in sources :

Example 21 with Primary

use of org.springframework.context.annotation.Primary in project thingsboard by thingsboard.

the class ThingsboardMessageConfiguration method messageSource.

@Bean
@Primary
public MessageSource messageSource() {
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasename("i18n/messages");
    messageSource.setDefaultEncoding("UTF-8");
    return messageSource;
}
Also used : ResourceBundleMessageSource(org.springframework.context.support.ResourceBundleMessageSource) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean)

Example 22 with Primary

use of org.springframework.context.annotation.Primary in project cloud-sea-towerman by huadahuang1983.

the class OAuthServerConfig method tokenServices.

@Primary
@Bean
public AuthorizationServerTokenServices tokenServices() {
    DefaultTokenServices defaultTokenServices = new DefaultTokenServices();
    defaultTokenServices.setTokenStore(tokenStore());
    defaultTokenServices.setSupportRefreshToken(true);
    defaultTokenServices.setClientDetailsService(clientDetailsService());
    // 有效期设置
    defaultTokenServices.setAccessTokenValiditySeconds((int) TimeUnit.HOURS.toSeconds(2));
    return defaultTokenServices;
}
Also used : DefaultTokenServices(org.springframework.security.oauth2.provider.token.DefaultTokenServices) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean)

Example 23 with Primary

use of org.springframework.context.annotation.Primary in project cloud-sea-towerman by huadahuang1983.

the class DataSourceConfig method druidDataSource.

@Bean
@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 24 with Primary

use of org.springframework.context.annotation.Primary in project Backend by FredBoat.

the class DatabaseConfiguration method mainDbConn.

@Primary
@Bean
public DatabaseConnection mainDbConn(DatabaseManager databaseManager) throws InterruptedException {
    // attempt to connect to the database a few times
    // this is relevant in a dockerized environment because after a reboot there is no guarantee that the db
    // container will be started before the fredboat one
    int dbConnectionAttempts = 0;
    DatabaseConnection mainDbConn = null;
    while ((mainDbConn == null || !mainDbConn.isAvailable()) && dbConnectionAttempts++ < 10) {
        try {
            if (mainDbConn != null) {
                mainDbConn.shutdown();
            }
            mainDbConn = databaseManager.getMainDbConn();
        } catch (Exception e) {
            log.info("Could not connect to the database. Retrying in a moment...", e);
            Thread.sleep(6000);
        }
    }
    if (mainDbConn == null || !mainDbConn.isAvailable()) {
        String message = "Could not establish database connection. Exiting...";
        log.error(message);
        System.exit(1);
    }
    return mainDbConn;
}
Also used : DatabaseConnection(space.npstr.sqlsauce.DatabaseConnection) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 25 with Primary

use of org.springframework.context.annotation.Primary in project spring-boot-admin by codecentric.

the class NotifierConfig method remindingNotifier.

@Primary
@Bean(initMethod = "start", destroyMethod = "stop")
public RemindingNotifier remindingNotifier() {
    // <2>
    RemindingNotifier notifier = new RemindingNotifier(filteringNotifier(), this.repository);
    notifier.setReminderPeriod(Duration.ofMinutes(10));
    notifier.setCheckReminderInverval(Duration.ofSeconds(10));
    return notifier;
}
Also used : RemindingNotifier(de.codecentric.boot.admin.server.notify.RemindingNotifier) Primary(org.springframework.context.annotation.Primary) 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