Search in sources :

Example 91 with Primary

use of org.springframework.context.annotation.Primary in project dhis2-core by dhis2.

the class DataSourceConfig method jdbcTemplate.

@Bean("jdbcTemplate")
@DependsOn("dataSource")
@Primary
public JdbcTemplate jdbcTemplate(@Qualifier("dataSource") DataSource dataSource) {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    jdbcTemplate.setFetchSize(1000);
    return jdbcTemplate;
}
Also used : NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) DependsOn(org.springframework.context.annotation.DependsOn) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean)

Example 92 with Primary

use of org.springframework.context.annotation.Primary in project dhis2-core by dhis2.

the class DataSourceConfig method dataSource.

@Bean("dataSource")
@DependsOn("actualDataSource")
@Primary
public DataSource dataSource(@Qualifier("actualDataSource") DataSource actualDataSource) {
    boolean enableQueryLogging = dhisConfig.isEnabled(ConfigurationKey.ENABLE_QUERY_LOGGING);
    if (!enableQueryLogging) {
        return actualDataSource;
    }
    PrettyQueryEntryCreator creator = new PrettyQueryEntryCreator();
    creator.setMultiline(true);
    SLF4JQueryLoggingListener listener = new SLF4JQueryLoggingListener();
    listener.setLogger("org.hisp.dhis.datasource.query");
    listener.setLogLevel(SLF4JLogLevel.INFO);
    listener.setQueryLogEntryCreator(creator);
    ProxyDataSourceBuilder b = ProxyDataSourceBuilder.create(actualDataSource).name("ProxyDS_DHIS2_" + dhisConfig.getProperty(ConfigurationKey.DB_POOL_TYPE) + "_" + CodeGenerator.generateCode(5)).logSlowQueryBySlf4j(Integer.parseInt(dhisConfig.getProperty(ConfigurationKey.SLOW_QUERY_LOGGING_THRESHOLD_TIME_MS)), TimeUnit.MILLISECONDS, SLF4JLogLevel.WARN).listener(listener).proxyResultSet();
    boolean elapsedTimeLogging = dhisConfig.isEnabled(ConfigurationKey.ELAPSED_TIME_QUERY_LOGGING_ENABLED);
    boolean methodLoggingEnabled = dhisConfig.isEnabled(ConfigurationKey.METHOD_QUERY_LOGGING_ENABLED);
    if (methodLoggingEnabled) {
        b.afterMethod(DataSourceConfig::executeAfterMethod);
    }
    if (elapsedTimeLogging) {
        b.afterQuery((execInfo, queryInfoList) -> log.info("Query took " + execInfo.getElapsedTime() + "msec"));
    }
    return b.build();
}
Also used : ProxyDataSourceBuilder(net.ttddyy.dsproxy.support.ProxyDataSourceBuilder) SLF4JQueryLoggingListener(net.ttddyy.dsproxy.listener.logging.SLF4JQueryLoggingListener) DependsOn(org.springframework.context.annotation.DependsOn) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean)

Example 93 with Primary

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

the class TestMailService method mailService.

@Bean
@Primary
public MailService mailService() throws ThingsboardException {
    MailService mailService = Mockito.mock(MailService.class);
    Mockito.doAnswer(new Answer<Void>() {

        public Void answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            String activationLink = (String) args[0];
            currentActivateToken = activationLink.split("=")[1];
            return null;
        }
    }).when(mailService).sendActivationEmail(Mockito.anyString(), Mockito.anyString());
    Mockito.doAnswer(new Answer<Void>() {

        public Void answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            String passwordResetLink = (String) args[0];
            currentResetPasswordToken = passwordResetLink.split("=")[1];
            return null;
        }
    }).when(mailService).sendResetPasswordEmailAsync(Mockito.anyString(), Mockito.anyString());
    return mailService;
}
Also used : MailService(org.thingsboard.rule.engine.api.MailService) InvocationOnMock(org.mockito.invocation.InvocationOnMock) 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