Search in sources :

Example 6 with Primary

use of org.springframework.context.annotation.Primary in project spring-boot-examples by ityouknow.

the class DataSource1Config method testSqlSessionFactory.

@Bean(name = "test1SqlSessionFactory")
@Primary
public SqlSessionFactory testSqlSessionFactory(@Qualifier("test1DataSource") DataSource dataSource) throws Exception {
    SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
    bean.setDataSource(dataSource);
    bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mybatis/mapper/test1/*.xml"));
    return bean.getObject();
}
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)

Example 7 with Primary

use of org.springframework.context.annotation.Primary in project earth-snow by justlive1.

the class WebConfig method jsonConverter.

@Primary
@Bean
public MappingJackson2HttpMessageConverter jsonConverter() {
    MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(objectMapper());
    converter.setSupportedMediaTypes(Arrays.asList(MediaType.APPLICATION_JSON_UTF8, MediaType.TEXT_PLAIN));
    return converter;
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean)

Example 8 with Primary

use of org.springframework.context.annotation.Primary in project earth-snow by justlive1.

the class WebConfig method objectMapper.

@Primary
@Bean
ObjectMapper objectMapper() {
    ObjectMapper mapper = new ObjectMapper();
    // 使用JsonView处理某个具体请求时Pojo转换成Json时显示内容
    mapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false);
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.setSerializationInclusion(Include.NON_NULL);
    return mapper;
}
Also used : ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean)

Example 9 with Primary

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

the class MasterDataSourceConfig method masterSqlSessionFactory.

@Bean(name = "masterSqlSessionFactory")
@Primary
public SqlSessionFactory masterSqlSessionFactory(@Qualifier("masterDataSource") DataSource masterDataSource) throws Exception {
    final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
    sessionFactory.setDataSource(masterDataSource);
    sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(MasterDataSourceConfig.MAPPER_LOCATION));
    return sessionFactory.getObject();
}
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)

Example 10 with Primary

use of org.springframework.context.annotation.Primary in project modesti by jlsalmon.

the class JpaConfig method coreTransactionManager.

@Bean
@Primary
public JpaTransactionManager coreTransactionManager(EntityManagerFactoryBuilder builder) {
    JpaTransactionManager transactionManager = new JpaTransactionManager();
    transactionManager.setEntityManagerFactory(coreEntityManagerFactory(builder).getObject());
    return transactionManager;
}
Also used : JpaTransactionManager(org.springframework.orm.jpa.JpaTransactionManager) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

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