Search in sources :

Example 61 with Primary

use of org.springframework.context.annotation.Primary in project mybatis.flying by limeng32.

the class SqlSessionFactory2Config method createSqlSessionFactory2Bean.

@Bean(name = "sqlSessionFactory2")
@Primary
public SqlSessionFactoryBean createSqlSessionFactory2Bean() throws IOException {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    /**
     * 设置datasource
     */
    sqlSessionFactoryBean.setDataSource(dataSource2);
    VFS.addImplClass(SpringBootVFS.class);
    /**
     * 设置mybatis configuration 扫描路径
     */
    sqlSessionFactoryBean.setConfigLocation(new ClassPathResource("Configuration.xml"));
    /**
     * 设置typeAlias 包扫描路径
     */
    sqlSessionFactoryBean.setTypeAliasesPackage("indi.mybatis.flying");
    /**
     * 添加mapper 扫描路径
     */
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    Resource[] ra1 = resolver.getResources("classpath*:indi/mybatis/flying/mapper*/*.xml");
    // 扫描映射文件
    sqlSessionFactoryBean.setMapperLocations(ra1);
    return sqlSessionFactoryBean;
}
Also used : ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ClassPathResource(org.springframework.core.io.ClassPathResource) Primary(org.springframework.context.annotation.Primary) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 62 with Primary

use of org.springframework.context.annotation.Primary in project esup-papercut by EsupPortail.

the class CasConfig method authenticationEntryPoint.

@Bean
@Primary
public AuthenticationEntryPoint authenticationEntryPoint(ServiceProperties sP) {
    CasAuthenticationEntryPoint entryPoint = new CasAuthenticationEntryPoint();
    entryPoint.setLoginUrl(url + "/login");
    entryPoint.setServiceProperties(sP);
    return entryPoint;
}
Also used : CasAuthenticationEntryPoint(org.springframework.security.cas.web.CasAuthenticationEntryPoint) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean)

Example 63 with Primary

use of org.springframework.context.annotation.Primary in project CzechIdMng by bcvsolutions.

the class AsyncConfig method getAsyncExecutor.

/**
 * Scaled for combination of computing  (e.g. for automatic roles) and I/O operations (synchronization) tasks. Uses cpu count as default pool size,
 * leaves some space for event thread pool, which has higher priority, see {@link #eventExecutor()}.
 */
@Primary
@Override
@Bean(name = SchedulerConfiguration.TASK_EXECUTOR_NAME)
public Executor getAsyncExecutor() {
    int cpuCount = Runtime.getRuntime().availableProcessors();
    // 
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    int corePoolSize = env.getProperty(SchedulerConfiguration.PROPERTY_TASK_EXECUTOR_CORE_POOL_SIZE, Integer.class, cpuCount);
    // ~4
    executor.setCorePoolSize(corePoolSize);
    int maxPoolSize = env.getProperty(SchedulerConfiguration.PROPERTY_TASK_EXECUTOR_MAX_POOL_SIZE, Integer.class, corePoolSize * 2);
    // ~8
    executor.setMaxPoolSize(maxPoolSize);
    int queueCapacity = env.getProperty(SchedulerConfiguration.PROPERTY_TASK_EXECUTOR_QUEUE_CAPACITY, Integer.class, SchedulerConfiguration.DEFAULT_TASK_EXECUTOR_QUEUE_CAPACITY);
    executor.setQueueCapacity(queueCapacity);
    executor.setThreadPriority(env.getProperty(SchedulerConfiguration.PROPERTY_TASK_EXECUTOR_THREAD_PRIORITY, Integer.class, 5));
    // MODE_INHERITABLETHREADLOCAL mode is not recommended in environment where thread pools are used (old SecurityContext can be reused in next thread using.).
    // Instead that the DelegatingSecurityContextRunnable is used for delegating the SecurityContext to child the thread.
    // Same is applies for TransactionContext. You have to use DelegatingTransactionContextRunnable for delegating to the child thread.
    // Beware, you have to wrap every new Thread to this delegate objects (wrappers).
    executor.setTaskDecorator(runnable -> new DelegatingSecurityContextRunnable(new DelegatingTransactionContextRunnable(runnable)));
    executor.setThreadNamePrefix("base-task-executor-");
    executor.initialize();
    // 
    LOG.info("Task executor is initialized: corePoolSize [{}], maxPoolSize [{}], queueCapacity [{}]", corePoolSize, maxPoolSize, queueCapacity);
    // 
    return executor;
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) DelegatingSecurityContextRunnable(org.springframework.security.concurrent.DelegatingSecurityContextRunnable) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean)

Example 64 with Primary

use of org.springframework.context.annotation.Primary in project apollo by ctripcorp.

the class SkipAuthorizationConfiguration method permissionValidator.

@Primary
@Bean("permissionValidator")
public PermissionValidator permissionValidator() {
    final PermissionValidator mock = mock(PermissionValidator.class);
    when(mock.isSuperAdmin()).thenReturn(true);
    return mock;
}
Also used : PermissionValidator(com.ctrip.framework.apollo.portal.component.PermissionValidator) ConsumerPermissionValidator(com.ctrip.framework.apollo.openapi.auth.ConsumerPermissionValidator) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean)

Example 65 with Primary

use of org.springframework.context.annotation.Primary in project apollo by ctripcorp.

the class SkipAuthorizationConfiguration method consumerAuthUtil.

@Primary
@Bean
public ConsumerAuthUtil consumerAuthUtil() {
    final ConsumerAuthUtil mock = mock(ConsumerAuthUtil.class);
    when(mock.getConsumerId(any())).thenReturn(1L);
    return mock;
}
Also used : ConsumerAuthUtil(com.ctrip.framework.apollo.openapi.util.ConsumerAuthUtil) 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