Java Code Examples for org.springframework.context.annotation.Primary

The following are top voted examples for showing how to use org.springframework.context.annotation.Primary. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: springbootWeb   File: BusinessDatabaseConfig.java   Source Code and License 6 votes vote down vote up
@Bean
@Primary
public SqlSessionFactory businessSqlSessionFactory(@Qualifier("businessDataSource") DruidDataSource businessDataSource) throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(businessDataSource);
    //mybatis分页
    Properties props = new Properties();
    props.setProperty("dialect", "mysql");
    props.setProperty("reasonable", "true");
    props.setProperty("supportMethodsArguments", "true");
    props.setProperty("returnPageInfo", "check");
    props.setProperty("params", "count=countSql");
    PageHelper pageHelper = new PageHelper();
    pageHelper.setProperties(props);
    //添加插件
    sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources(MAPPERXML_LOCATION));
    return sqlSessionFactoryBean.getObject();
}
 
Example 2
Project: xm-ms-config   File: TestConfiguration.java   Source Code and License 6 votes vote down vote up
@Bean
@Primary
@SneakyThrows
public JGitRepository jGitRepository(ApplicationProperties applicationProperties, HazelcastInstance hazelcastInstance) {

    return new JGitRepository(applicationProperties.getGit(), new ReentrantLock()) {
        @Override
        protected void initRepository(){};
        @Override
        protected void pull(){};
        @Override
        protected void commitAndPush(String commitMsg){};
        @Override
        public List<com.icthh.xm.ms.configuration.domain.Configuration> findAll(){
            return emptyList();
        }
    };
}
 
Example 3
Project: mafia   File: DsMasterConfig.java   Source Code and License 6 votes vote down vote up
@Bean(name = ConfigConstant.NAME_DS_MASTER)
@Primary
@ConfigurationProperties(prefix = ConfigConstant.PREFIX_DS_MASTER)
public DataSource mafMasterDataSource() {
    logger.info("----- MAFIA master data source INIT -----");
    DruidDataSource ds = new DruidDataSource();
    try {
        ds.setFilters(env.getProperty("ds.filters"));
    } catch (SQLException e) {
        logger.warn("Data source set filters ERROR:", e);
    }
    ds.setMaxActive(NumberUtils.toInt(env.getProperty("ds.maxActive"), 90));
    ds.setInitialSize(NumberUtils.toInt(env.getProperty("ds.initialSize"), 10));
    ds.setMaxWait(NumberUtils.toInt(env.getProperty("ds.maxWait"), 60000));
    ds.setMinIdle(NumberUtils.toInt(env.getProperty("ds.minIdle"), 1));
    ds.setTimeBetweenEvictionRunsMillis(NumberUtils.toInt(env.getProperty("ds.timeBetweenEvictionRunsMillis"), 60000));
    ds.setMinEvictableIdleTimeMillis(NumberUtils.toInt(env.getProperty("ds.minEvictableIdleTimeMillis"), 300000));
    ds.setValidationQuery(env.getProperty("ds.validationQuery"));
    ds.setTestWhileIdle(BooleanUtils.toBoolean(env.getProperty("ds.testWhileIdle")));
    ds.setTestOnBorrow(BooleanUtils.toBoolean(env.getProperty("ds.testOnBorrow")));
    ds.setTestOnReturn(BooleanUtils.toBoolean(env.getProperty("ds.testOnReturn")));
    ds.setPoolPreparedStatements(BooleanUtils.toBoolean(env.getProperty("ds.poolPreparedStatements")));
    ds.setMaxOpenPreparedStatements(NumberUtils.toInt(env.getProperty("ds.maxOpenPreparedStatements"), 20));
    return ds;
}
 
Example 4
Project: xm-gate   File: CacheConfiguration.java   Source Code and License 6 votes vote down vote up
@Bean
@Primary
public HazelcastInstance hazelcastInstance(JHipsterProperties jHipsterProperties) {
    log.debug("Configuring Hazelcast");
    HazelcastInstance hazelCastInstance = Hazelcast.getHazelcastInstanceByName("gate");
    if (hazelCastInstance != null) {
        log.debug("Hazelcast already initialized");
        return hazelCastInstance;
    }
    Config config = new Config();
    config.setInstanceName("gate");
    config.getNetworkConfig().setPort(5701);
    config.getNetworkConfig().setPortAutoIncrement(true);

    // In development, remove multicast auto-configuration
    if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) {
        System.setProperty("hazelcast.local.localAddress", "127.0.0.1");

        config.getNetworkConfig().getJoin().getAwsConfig().setEnabled(false);
        config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
        config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(false);
    }
    config.getMapConfigs().put("default", initializeDefaultMapConfig());
    config.getMapConfigs().put("com.icthh.xm.gate.domain.*", initializeDomainMapConfig(jHipsterProperties));
    return Hazelcast.newHazelcastInstance(config);
}
 
Example 5
Project: Agent-Benchmarks   File: DataSourceConfiguration.java   Source Code and License 5 votes vote down vote up
@Bean
@Primary
public DataSource getDataSource() {
    HikariConfig config = new HikariConfig();
    config.setDriverClassName("com.mysql.jdbc.Driver");
    config.setJdbcUrl("jdbc:mysql://localhost:3306/test");
    config.setUsername("root");
    config.setPassword("root");
    config.setMaximumPoolSize(500);
    config.setMinimumIdle(10);
    return new HikariDataSource(config);
}
 
Example 6
Project: spring-security-oauth2-boot   File: OAuth2RestOperationsConfiguration.java   Source Code and License 5 votes vote down vote up
@Bean
@ConfigurationProperties(prefix = "security.oauth2.client")
@Primary
public ClientCredentialsResourceDetails oauth2RemoteResource() {
	ClientCredentialsResourceDetails details = new ClientCredentialsResourceDetails();
	return details;
}
 
Example 7
Project: nifi-registry   File: DataSourceFactory.java   Source Code and License 5 votes vote down vote up
@Bean
@Primary
public DataSource getDataSource() {
    if (connectionPool == null) {
        // locate the repository directory
        final String repositoryDirectoryPath = properties.getDatabaseDirectory();

        // ensure the repository directory is specified
        if (repositoryDirectoryPath == null) {
            throw new NullPointerException("Database directory must be specified.");
        }

        // create a handle to the repository directory
        final File repositoryDirectory = new File(repositoryDirectoryPath);

        // get a handle to the database file
        final File databaseFile = new File(repositoryDirectory, DATABASE_FILE_NAME);

        // format the database url
        String databaseUrl = "jdbc:h2:" + databaseFile + ";AUTOCOMMIT=OFF;DB_CLOSE_ON_EXIT=FALSE;LOCK_MODE=3";
        String databaseUrlAppend = properties.getDatabaseUrlAppend();
        if (StringUtils.isNotBlank(databaseUrlAppend)) {
            databaseUrl += databaseUrlAppend;
        }

        // create the pool
        connectionPool = JdbcConnectionPool.create(databaseUrl, DB_USERNAME_PASSWORD, DB_USERNAME_PASSWORD);
        connectionPool.setMaxConnections(MAX_CONNECTIONS);
    }

    return connectionPool;
}
 
Example 8
Project: mafia   File: DsMasterConfig.java   Source Code and License 5 votes vote down vote up
@Bean(name = ConfigConstant.NAME_DS_SSF_MASTER)
@Primary
public SqlSessionFactory mafMasterSqlSessionFactory(@Qualifier(ConfigConstant.NAME_DS_MASTER) DataSource mafMasterDataSource) throws Exception {
    logger.info("----- MAFIA master data source sql session factory INIT -----");
    final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
    sessionFactory.setDataSource(mafMasterDataSource);
    sessionFactory.setConfigLocation(new ClassPathResource(ConfigConstant.NAME_MYBATIS_CONFIG));
    return sessionFactory.getObject();
}
 
Example 9
Project: REST-Web-Services   File: WebDatasourceConfig.java   Source Code and License 5 votes vote down vote up
/**
 * Get data source.
 *
 * @return Data source
 */
@Primary
@Bean
@ConfigurationProperties(prefix="spring.datasource")
public DataSource getDatasource() {
    return DataSourceBuilder.create().build();
}
 
Example 10
Project: dockerunit   File: AppRunner.java   Source Code and License 5 votes vote down vote up
@Bean
@Primary
public Properties loadProperties() throws FileNotFoundException, IOException {
	String propsLocation = System.getProperty("properties.location");
	Properties props = new Properties();
	props.load(new FileReader(new File(propsLocation)));
	return props;
}
 
Example 11
Project: MI-S   File: DataBaseConfiguration.java   Source Code and License 5 votes vote down vote up
/**
 * 主库配置(负责写)
 * @return
 */
@Bean(name="masterDataSource")
@Primary
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource writeDataSource() {
    log.info("-------------------- Master DataSource init ---------------------");
    return DataSourceBuilder.create().type(dataSourceType).build();
}
 
Example 12
Project: springboot-copy   File: MasterDataSourceConfig.java   Source Code and License 5 votes vote down vote up
@Bean(name = "masterDataSource")
@Primary
public DataSource masterDataSource() {
    DruidDataSource dataSource = new DruidDataSource();
    dataSource.setDriverClassName(driverClass);
    dataSource.setUrl(url);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    return dataSource;
}
 
Example 13
Project: cmc-claim-store   File: JacksonConfiguration.java   Source Code and License 5 votes vote down vote up
@Bean
@Primary
public ObjectMapper objectMapper() {
    return new ObjectMapper()
        .registerModule(new Jdk8Module())
        .registerModule(new ParameterNamesModule(JsonCreator.Mode.PROPERTIES))
        .registerModule(new JavaTimeModule()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
        .setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
        .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
}
 
Example 14
Project: Building-Web-Apps-with-Spring-5-and-Angular   File: AuthServerOAuth2Config.java   Source Code and License 5 votes vote down vote up
@Bean
@Primary
public DefaultTokenServices tokenServices() {
    final DefaultTokenServices defaultTokenServices = new DefaultTokenServices();
    defaultTokenServices.setTokenStore(tokenStore());
    defaultTokenServices.setSupportRefreshToken(true);
    return defaultTokenServices;
}
 
Example 15
Project: amv-access-api-poc   File: SwaggerSqliteTestDatabaseConfig.java   Source Code and License 5 votes vote down vote up
@Bean
@Primary
public DataSource dataSource() {
    DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();
    dataSourceBuilder.driverClassName(org.sqlite.JDBC.class.getName());
    dataSourceBuilder.url("jdbc:sqlite:~amv-access-swagger-docs.db?journal_mode=wal");
    return dataSourceBuilder.build();
}
 
Example 16
Project: spring-boot-mybatisplus-multiple-datasource   File: DataSourceConfig.java   Source Code and License 5 votes vote down vote up
@Bean
@Primary
public MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean ( DynamicMultipleDataSource dynamicMultipleDataSource ) {
    MybatisSqlSessionFactoryBean sqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource( dynamicMultipleDataSource );
    return sqlSessionFactoryBean;
}
 
Example 17
Project: mark-framework   File: DruidConfiguration.java   Source Code and License 5 votes vote down vote up
@Bean
@Primary
public DataSource dataSource() {
    DruidDataSource datasource = new DruidDataSource();
    datasource.setUrl(url);
    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) {
        System.err.println("druid configuration initialization filter: " + e);
    }
    datasource.setConnectionProperties(connectionProperties);
    return datasource;
}
 
Example 18
Project: easynetcn-cloud   File: OneJpaConfig.java   Source Code and License 5 votes vote down vote up
@Primary
@Bean(name = "oneEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder) {
	DataSource dataSource = dataSource();

	return builder.dataSource(dataSource).packages("com.easynetcn.cloud.one.web.data.entity")
			.persistenceUnit("onePersistenceUnit").build();
}
 
Example 19
Project: Oauth2-Stateless-Authentication-with-Spring-and-JWT-Token   File: AuthorizationServerConfig.java   Source Code and License 5 votes vote down vote up
@Bean
@Primary
public DefaultTokenServices tokenServices() {
    DefaultTokenServices defaultTokenServices = new DefaultTokenServices();
    defaultTokenServices.setTokenStore(tokenStore());
    defaultTokenServices.setSupportRefreshToken(true);
    defaultTokenServices.setTokenEnhancer(accessTokenConverter());
    return defaultTokenServices;
}
 
Example 20
Project: spring-cloud-gcp   File: StackdriverTraceAutoConfiguration.java   Source Code and License 5 votes vote down vote up
@Primary
@Bean
@ConditionalOnMissingBean(name = "traceConsumer")
public TraceConsumer traceConsumer(
		TraceServiceClientTraceConsumer traceServiceClientTraceConsumer,
		Sizer<Trace> traceSizer,
		@Qualifier("scheduledBufferingExecutorService")
				ScheduledExecutorService executorService,
		GcpTraceProperties gcpTraceProperties) {
	return new ScheduledBufferingTraceConsumer(
			traceServiceClientTraceConsumer,
			traceSizer, gcpTraceProperties.getBufferSizeBytes(),
			gcpTraceProperties.getScheduledDelaySeconds(), executorService);
}
 
Example 21
Project: springboot   File: MasterDataSourceConfig.java   Source Code and License 5 votes vote down vote up
@Bean(name="masterDataSource")
//标志这个 Bean 如果在多个同类 Bean 候选时,该 Bean 优先被考虑。「多数据源配置的时候注意,必须要有一个主数据源,用 @Primary 标志该 Bean
@Primary
public DataSource masterDataSource(){
	DruidDataSource druidDataSource = new DruidDataSource();
	druidDataSource.setUrl(url);
	druidDataSource.setUsername(user);
	druidDataSource.setPassword(password);
	druidDataSource.setDriverClassName(driverClass);
	return druidDataSource;
	
}
 
Example 22
Project: springboot   File: DruidDataSourceConfig.java   Source Code and License 5 votes vote down vote up
@Bean(name="dataSource")
//标志这个 Bean 如果在多个同类 Bean 候选时,该 Bean 优先被考虑。「多数据源配置的时候注意,必须要有一个主数据源,用 @Primary 标志该 Bean
@Primary
public DataSource dataSource(){
	DruidDataSource druidDataSource = new DruidDataSource();
	druidDataSource.setUrl(url);
	druidDataSource.setUsername(user);
	druidDataSource.setPassword(password);
	druidDataSource.setDriverClassName(driverClass);
	return druidDataSource;
	
}
 
Example 23
Project: MI-S   File: DataBaseConfiguration.java   Source Code and License 5 votes vote down vote up
/**
 * 主库配置(负责写)
 * @return
 */
@Bean(name="masterDataSource", destroyMethod = "close", initMethod="init")
@Primary
@ConfigurationProperties(prefix = "spring.datasource",locations = "classpath:application.properties")
public DataSource writeDataSource() {
    log.info("-------------------- Master DataSource init ---------------------");
    return DataSourceBuilder.create().type(dataSourceType).build();
}
 
Example 24
Project: springboot-course   File: CourseDbConfig.java   Source Code and License 5 votes vote down vote up
@Bean(name = "courseSqlSessionFactory")
@Primary
public SqlSessionFactory courseSqlSessionFactory(@Qualifier("courseDataSource") DataSource dataSource) throws Exception {
    SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
    bean.setDataSource(dataSource);
    return bean.getObject();
}
 
Example 25
Project: SpringBoot-Study   File: MasterDruidDataSourceConfig.java   Source Code and License 5 votes vote down vote up
@ConfigurationProperties(prefix = "spring.datasource.master")
@Bean(name = "masterDataSource")
@Primary
public DataSource masterDataSource() {
    DruidDataSource dataSource = new DruidDataSource();
    try {
        dataSource.setFilters("stat,wall,log4j");
    } catch (SQLException e) {
        //
    }
    return dataSource;
}
 
Example 26
Project: data-migration   File: DataSourceConfiguration.java   Source Code and License 5 votes vote down vote up
@Bean
@Primary
@Qualifier("jpaDataSource")
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource createJpaDataSource() {
    return DataSourceBuilder.create().type(dataSourceType).build();
}
 
Example 27
Project: springrestdoc   File: RestDocsApplication.java   Source Code and License 5 votes vote down vote up
@Primary
@Bean(name = "objectMapper")
ObjectMapper objectMapper() {
    springHateoasObjectMapper.configure(SerializationFeature.INDENT_OUTPUT, true);
    springHateoasObjectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    springHateoasObjectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
    return springHateoasObjectMapper;
}
 
Example 28
Project: springuni-particles   File: AbstractJpaRepositoryConfiguration.java   Source Code and License 5 votes vote down vote up
/**
 * Creates the entity manager factory.
 *
 * @param dataSource the data source to use
 * @return entity manager factory
 */
@Bean
@Primary
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) {
  LocalContainerEntityManagerFactoryBean entityManagerFactoryBean =
      new LocalContainerEntityManagerFactoryBean();

  entityManagerFactoryBean.setDataSource(dataSource);

  JpaVendorAdapter jpaVendorAdapter = createJpaVendorAdapter();
  entityManagerFactoryBean.setJpaVendorAdapter(jpaVendorAdapter);

  Map<String, String> jpaPropertyMap = getJpaPropertyMap();
  entityManagerFactoryBean.setJpaPropertyMap(jpaPropertyMap);

  getMappingResources().ifPresent(entityManagerFactoryBean::setMappingResources);
  getPackagesToScan().ifPresent(entityManagerFactoryBean::setPackagesToScan);

  // https://hibernate.atlassian.net/browse/HHH-5303#comment-44439
  entityManagerFactoryBean.setSharedCacheMode(ENABLE_SELECTIVE);

  customizeEntityManagerFactoryBean(entityManagerFactoryBean);

  return entityManagerFactoryBean;
}
 
Example 29
Project: poppynotes   File: TestConfig.java   Source Code and License 5 votes vote down vote up
@Primary
@Bean(name="testRestTemplate")
RestTemplate restTemplate() {
	RestTemplate template = new RestTemplate();
	template.setErrorHandler(getResponseErrorHandler());

	return template;
}
 
Example 30
Project: app-ms   File: SpringTestConfiguration.java   Source Code and License 5 votes vote down vote up
@Bean
@Primary
public HttpServerOptions httpServerOptions() {

    return new HttpServerOptions()
        .setPort(SocketUtils.findAvailableTcpPort());

}
 
Example 31
Project: autotest   File: UserDataSourceConfig.java   Source Code and License 5 votes vote down vote up
@Bean(name = "userSqlSessionFactory")
@Primary
public SqlSessionFactory userSqlSessionFactory(@Qualifier("userDataSource") DataSource userDataSource)
		throws Exception {
	final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
	sessionFactory.setDataSource(userDataSource);
	return sessionFactory.getObject();
}
 
Example 32
Project: camel-springboot   File: StoredProcTest.java   Source Code and License 5 votes vote down vote up
@Bean(value = "cityInfoDS")
@Primary
public DataSource createCityInfoDS(){
	return new EmbeddedDatabaseBuilder()
			.setType(EmbeddedDatabaseType.DERBY)
			.setName("CityInfoDatabase")
			.addScript("sql/GETZIPS.sql")
			.addScript("sql/StoredProcTest.sql")
			.build();
}
 
Example 33
Project: spring-boot-multidatasource   File: DataSourceConfiguration.java   Source Code and License 5 votes vote down vote up
@Bean
@Primary
@ConfigurationProperties(prefix = "spring.datasource.dbcp2")
public org.apache.commons.dbcp2.BasicDataSource dataSource(
		@Qualifier("dataSourceProperties") DataSourceProperties properties) {
	return createDataSource(properties,
			org.apache.commons.dbcp2.BasicDataSource.class);
}
 
Example 34
Project: springboot-security-wechat   File: AuditDsConfig.java   Source Code and License 5 votes vote down vote up
/**
 * 数据源对象
 * @return
 */
@Bean
@Primary
@ConfigurationProperties("first.datasource")
public DataSource firstDataSource() {
    return firstDataSourceProperties().initializeDataSourceBuilder().build();
}
 
Example 35
Project: kubernetes-client   File: KubernetesClientConfig.java   Source Code and License 5 votes vote down vote up
@Primary
@Bean
public ApiClient kubernetesClient() {

    if (LocalKubeconfigApiClient.getConfigFile().exists())
        return new LocalKubeconfigApiClient();

    if (InClusterApiClient.getTokenFile().exists())
        return new InClusterApiClient();

    throw new RuntimeException("Could not auto-detect the Kubernetes client configuration, as neither " +
            LocalKubeconfigApiClient.getConfigFile().getAbsolutePath() + " nor " +
            InClusterApiClient.getTokenFile().getAbsolutePath() + " exist.");
}
 
Example 36
Project: my-spring-boot-project   File: DynamicDataSourceConfig.java   Source Code and License 5 votes vote down vote up
@Bean
@Primary
public DynamicDataSource dataSource(DataSource firstDataSource, DataSource secondDataSource) {
    Map<String, DataSource> targetDataSources = new HashMap<>();
    targetDataSources.put(DataSourceNames.FIRST, firstDataSource);
    targetDataSources.put(DataSourceNames.SECOND, secondDataSource);
    return new DynamicDataSource(firstDataSource, targetDataSources);
}
 
Example 37
Project: holon-datastore-jpa   File: TestEnableDatastore.java   Source Code and License 5 votes vote down vote up
@Bean
@Primary
public FactoryBean<EntityManagerFactory> entityManagerFactory(DataSource dataSource) {
	LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
	emf.setDataSource(dataSource);
	HibernateJpaVendorAdapter va = new HibernateJpaVendorAdapter();
	va.setShowSql(true);
	emf.setJpaVendorAdapter(va);
	emf.setPackagesToScan(TestJpaDomain1.class.getPackage().getName());
	return emf;
}
 
Example 38
Project: springboot-multi-datasource   File: DataSource1Config.java   Source Code and License 5 votes vote down vote up
@Bean(name = "test1SqlSessionFactory")
@Primary
public SqlSessionFactory testSqlSessionFactory(@Qualifier("test1DataSource") DataSource dataSource) throws Exception {
    SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
    bean.setDataSource(dataSource);
    return bean.getObject();
}
 
Example 39
Project: research-graphql   File: ApplicationTestConfiguration.java   Source Code and License 5 votes vote down vote up
@Bean
@Primary
UserAdaptor getUserAdaptor() {
    UserAdaptor mock = mock(UserAdaptor.class);
    when(mock.getAllUsers())
            .thenReturn(new ArrayList<>(mapUsers.values()));
    when(mock.getUser(anyString()))
            .then((inv) -> mapUsers.get(inv.getArgumentAt(0, String.class)));
    return mock;
}
 
Example 40
Project: app-ms   File: SpringTestConfiguration.java   Source Code and License 5 votes vote down vote up
@Bean
@Primary
public HttpServerOptions httpServerOptions() {

    return new HttpServerOptions()
        .setPort(SocketUtils.findAvailableTcpPort());

}