Java Code Examples for org.springframework.beans.factory.annotation.Qualifier

The following examples show how to use org.springframework.beans.factory.annotation.Qualifier. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: erp-framework   Source File: FramedbConfig.java    License: MIT License 6 votes vote down vote up
@Bean(name = "framedbSqlSessionFactory")
public SqlSessionFactory testSqlSessionFactory(@Qualifier("framedbDataSource") DataSource dataSource) throws Exception {
    SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
    bean.setPlugins(new Interceptor[]{ sqlInterceptor});

    bean.setDataSource(dataSource);

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();

    Resource[] res = resolver.getResources("classpath:mapper/**");
    for (int i =0;i< res.length;i++) {
        if(res[i].getFilename().indexOf("xml")==-1){
            res[i] = null;
        }
    }
    bean.setMapperLocations(res);

    return bean.getObject();
}
 
Example 2
Source Project: rabbitmq-operator   Source File: ControllerConfig.java    License: Apache License 2.0 6 votes vote down vote up
@Bean
@Qualifier("LABELS_TO_WATCH")
public Map<String, String> labelsToWatch() {
    final ImmutableMap.Builder<String, String> mapBuilder = ImmutableMap.builder();

    if (System.getenv().containsKey(WATCH_LABELS_ENV_VAR)) {
        final String watchLabels = System.getenv().get(WATCH_LABELS_ENV_VAR);
        for (final String label : watchLabels.split(",")) {
            if (label.contains("=")) {
                final String[] keyValue = label.split("=");
                mapBuilder.put(keyValue[0], keyValue[1]);
            }
        }
    }

    return mapBuilder.build();
}
 
Example 3
@Test
public void autowiredFieldDoesNotResolveWithBaseQualifierAndNonDefaultValueAndMultipleMatchingCandidates() {
	GenericApplicationContext context = new GenericApplicationContext();
	ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
	cavs1.addGenericArgumentValue("the real juergen");
	RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
	person1.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "juergen"));
	ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
	cavs2.addGenericArgumentValue("juergen imposter");
	RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
	person2.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "juergen"));
	context.registerBeanDefinition("juergen1", person1);
	context.registerBeanDefinition("juergen2", person2);
	context.registerBeanDefinition("autowired",
			new RootBeanDefinition(QualifiedConstructorArgumentWithBaseQualifierNonDefaultValueTestBean.class));
	AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
	try {
		context.refresh();
		fail("expected BeanCreationException");
	}
	catch (BeanCreationException e) {
		assertTrue(e instanceof UnsatisfiedDependencyException);
		assertEquals("autowired", e.getBeanName());
	}
}
 
Example 4
@Test
public void autowiredFieldResolvesWithBaseQualifierAndDefaultValue() {
	GenericApplicationContext context = new GenericApplicationContext();
	ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
	cavs1.addGenericArgumentValue(JUERGEN);
	RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
	ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
	cavs2.addGenericArgumentValue(MARK);
	RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
	person2.addQualifier(new AutowireCandidateQualifier(Qualifier.class));
	context.registerBeanDefinition(JUERGEN, person1);
	context.registerBeanDefinition(MARK, person2);
	context.registerBeanDefinition("autowired",
			new RootBeanDefinition(QualifiedFieldWithBaseQualifierDefaultValueTestBean.class));
	AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
	context.refresh();
	QualifiedFieldWithBaseQualifierDefaultValueTestBean bean =
			(QualifiedFieldWithBaseQualifierDefaultValueTestBean) context.getBean("autowired");
	assertEquals(MARK, bean.getPerson().getName());
}
 
Example 5
@Test
public void autowiredFieldDoesNotResolveWithBaseQualifierAndNonDefaultValueAndMultipleMatchingCandidates() {
	GenericApplicationContext context = new GenericApplicationContext();
	ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
	cavs1.addGenericArgumentValue("the real juergen");
	RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
	person1.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "juergen"));
	ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
	cavs2.addGenericArgumentValue("juergen imposter");
	RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
	person2.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "juergen"));
	context.registerBeanDefinition("juergen1", person1);
	context.registerBeanDefinition("juergen2", person2);
	context.registerBeanDefinition("autowired",
			new RootBeanDefinition(QualifiedConstructorArgumentWithBaseQualifierNonDefaultValueTestBean.class));
	AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
	try {
		context.refresh();
		fail("expected BeanCreationException");
	}
	catch (BeanCreationException e) {
		assertTrue(e instanceof UnsatisfiedDependencyException);
		assertEquals("autowired", e.getBeanName());
	}
}
 
Example 6
Source Project: spring-analysis-note   Source File: QualifierAnnotationTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testQualifiedByParentValue() {
	StaticApplicationContext parent = new StaticApplicationContext();
	GenericBeanDefinition parentLarry = new GenericBeanDefinition();
	parentLarry.setBeanClass(Person.class);
	parentLarry.getPropertyValues().add("name", "ParentLarry");
	parentLarry.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "parentLarry"));
	parent.registerBeanDefinition("someLarry", parentLarry);
	GenericBeanDefinition otherLarry = new GenericBeanDefinition();
	otherLarry.setBeanClass(Person.class);
	otherLarry.getPropertyValues().add("name", "OtherLarry");
	otherLarry.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "otherLarry"));
	parent.registerBeanDefinition("someOtherLarry", otherLarry);
	parent.refresh();

	StaticApplicationContext context = new StaticApplicationContext(parent);
	BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
	reader.loadBeanDefinitions(CONFIG_LOCATION);
	context.registerSingleton("testBean", QualifiedByParentValueTestBean.class);
	context.refresh();
	QualifiedByParentValueTestBean testBean = (QualifiedByParentValueTestBean) context.getBean("testBean");
	Person person = testBean.getLarry();
	assertEquals("ParentLarry", person.getName());
}
 
Example 7
Source Project: SpringBootLearn   Source File: WebSecurityConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Autowired
public WebSecurityConfig(JwtAuthenticationEntryPoint unauthorizedHandler,
                         @Qualifier("RestAuthenticationAccessDeniedHandler") AccessDeniedHandler accessDeniedHandler,
                         JwtAuthenticationTokenFilter authenticationTokenFilter) {
    this.unauthorizedHandler = unauthorizedHandler;
    this.accessDeniedHandler = accessDeniedHandler;
    this.authenticationTokenFilter = authenticationTokenFilter;
}
 
Example 8
@Bean("jdbcDirectoryBasedFileConfigurationLoader")
public DirectoryBasedFileConfigurationLoader<NamedConnectionConfiguration> jdbcDirectoryBasedFileConfigurationLoader(
        @Autowired PropertiesNamedConnectionConfigurationParser propertiesConfigurationParser,
        @Autowired @Qualifier("filenameSupplier") Supplier<String, String> filenameSupplier,
        @Autowired @Qualifier("configurationIdSupplier") Supplier<String, String> configurationIdSupplier) {
    DirectoryBasedFileConfigurationLoader<NamedConnectionConfiguration> loader = new DirectoryBasedFileConfigurationLoader<NamedConnectionConfiguration>();
    loader.setFilenameSupplier(filenameSupplier);
    loader.setConfigurationIdSupplier(configurationIdSupplier);
    loader.setConfigurationParser(propertiesConfigurationParser);
    return loader;
}
 
Example 9
@Bean
public Cache<String, NamedConnectionConfiguration> jdbcConnectionConfigurationCache(
        @Autowired @Qualifier("jdbcDirectoryBasedFileConfigurationLoader")
                DirectoryBasedFileConfigurationLoader<NamedConnectionConfiguration> loader,
        @Autowired @Qualifier("timer")
                Timer timer) {
    return CacheBuilder.<String, NamedConnectionConfiguration>newBuilder()
            .loader(new ConfigurationCacheLoaderAdapter<>(loader))
            .timer(timer)
            .build();
}
 
Example 10
@Bean("jdbcDirectoryBasedFileConfigurationWriter")
public DirectoryBasedFileConfigurationWriter<NamedConnectionConfiguration> directoryBasedFileConfigurationWriter(
        @Autowired PropertiesNamedConnectionConfigurationSerializer serializer,
        @Autowired @Qualifier("filenameSupplier") Supplier<String, String> filenameSupplier) {
    DirectoryBasedFileConfigurationWriter<NamedConnectionConfiguration> writer = new DirectoryBasedFileConfigurationWriter<NamedConnectionConfiguration>();
    writer.setFilenameSupplier(filenameSupplier);
    writer.setConfigurationSerializer(serializer);
    writer.setEncoding("iso-8859-1");
    return writer;
}
 
Example 11
@Bean(DATABASE_PREFIX + "SqlSessionTemplate")
public SqlSessionTemplate getSqlSessionTemplate(@Qualifier(DATABASE_PREFIX + "SqlSessionFactory") SqlSessionFactory sqlSessionFactory) {
    ExecutorType executorType = this.properties.getExecutorType();
    if (executorType != null) {
        return new SqlSessionTemplate(sqlSessionFactory, executorType);
    } else {
        return new SqlSessionTemplate(sqlSessionFactory);
    }
}
 
Example 12
Source Project: enode   Source File: EnodeAutoConfiguration.java    License: MIT License 5 votes vote down vote up
@Bean(name = "defaultProcessingCommandHandler")
public DefaultProcessingCommandHandler defaultProcessingCommandHandler(
        IEventStore eventStore,
        ICommandHandlerProvider commandHandlerProvider,
        ITypeNameProvider typeNameProvider,
        IEventCommittingService eventService,
        IMemoryCache memoryCache,
        @Qualifier(value = "applicationMessagePublisher") IMessagePublisher<IApplicationMessage> applicationMessagePublisher,
        @Qualifier(value = "publishableExceptionPublisher") IMessagePublisher<IDomainException> publishableExceptionPublisher
) {
    return new DefaultProcessingCommandHandler(eventStore, commandHandlerProvider, typeNameProvider, eventService, memoryCache, applicationMessagePublisher, publishableExceptionPublisher);
}
 
Example 13
Source Project: RestDoc   Source File: SpringSwagger3Configuration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
SpringSwagger3Controller _springSwagger3Controller(@Qualifier("swagger3") IRestDocParser docParser) {
    SwaggerUIConfiguration uiConfiguration;
    try {
        uiConfiguration = _applicationContext.getBean(SwaggerUIConfiguration.class);
    } catch (NoSuchBeanDefinitionException e) {
        uiConfiguration = new SwaggerUIConfiguration();
    }
    var controller = new SpringSwagger3Controller(docParser, uiConfiguration);
    return controller;
}
 
Example 14
Source Project: rabbitmq-operator   Source File: ControllerConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public NetworkPartitionResourceController networkPartitionResourceController(
        final KubernetesClient client,
        @Qualifier("LABELS_TO_WATCH") final Map<String, String> labelsToWatch
) {
    return new NetworkPartitionResourceController(client, labelsToWatch);
}
 
Example 15
Source Project: rabbitmq-operator   Source File: ControllerConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public SecretsController secretsController(
        final KubernetesClient client,
        @Qualifier("LABELS_TO_WATCH") final Map<String, String> labelsToWatch
) {
    return new SecretsController(client, labelsToWatch, (val) -> new String(Base64.getDecoder().decode(val), StandardCharsets.UTF_8));
}
 
Example 16
Source Project: rabbitmq-operator   Source File: ControllerConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public ServicesController servicesController(
        final KubernetesClient client,
        @Qualifier("LABELS_TO_WATCH") final Map<String, String> labelsToWatch
) {
    return new ServicesController(client, labelsToWatch);
}
 
Example 17
Source Project: rabbitmq-operator   Source File: ControllerConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public StatefulSetController statefulSetController(
        final KubernetesClient client,
        @Qualifier("LABELS_TO_WATCH") final Map<String, String> labelsToWatch,
        final PodController podController
) {
    return new StatefulSetController(client, labelsToWatch, podController);
}
 
Example 18
Source Project: light-reading-cloud   Source File: MybatisConfig.java    License: MIT License 5 votes vote down vote up
/** 工厂配置 */
@Bean
public SqlSessionFactory sqlSessionFactoryBean(@Qualifier("bookCenterDataSource") DataSource dataSource) throws Exception {
    // 设置数据源
    SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
    factory.setDataSource(dataSource);

    // 添加XML映射
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    factory.setMapperLocations(resolver.getResources(MAPPER_LOCATIONS));

    //添加插件
    factory.setPlugins(new Interceptor[]{ this.getPageHelper() });
    return factory.getObject();
}
 
Example 19
Source Project: rabbitmq-operator   Source File: AppConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public ClusterAwareExecutor clusterAwareExecutor(
        @Qualifier("STANDARD_EXECUTOR") final ExecutorService executor,
        final NamedSemaphores namedSemaphores
) {
    return new ClusterAwareExecutor(executor, namedSemaphores);
}
 
Example 20
Source Project: cubeai   Source File: UaaSignatureVerifierClient.java    License: Apache License 2.0 5 votes vote down vote up
public UaaSignatureVerifierClient(DiscoveryClient discoveryClient, @Qualifier("loadBalancedRestTemplate") RestTemplate restTemplate,
                              OAuth2Properties oAuth2Properties) {
    this.restTemplate = restTemplate;
    this.oAuth2Properties = oAuth2Properties;
    // Load available UAA servers
    discoveryClient.getServices();
}
 
Example 21
Source Project: rqueue   Source File: RqueueUtilityServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Autowired
public RqueueUtilityServiceImpl(
    RqueueConfig rqueueConfig,
    RqueueWebConfig rqueueWebConfig,
    @Qualifier("stringRqueueRedisTemplate") RqueueRedisTemplate<String> stringRqueueRedisTemplate,
    RqueueSystemConfigDao rqueueSystemConfigDao,
    RqueueMessageTemplate rqueueMessageTemplate,
    RqueueMessageMetadataService messageMetadataService) {
  this.stringRqueueRedisTemplate = stringRqueueRedisTemplate;
  this.rqueueSystemConfigDao = rqueueSystemConfigDao;
  this.rqueueWebConfig = rqueueWebConfig;
  this.rqueueConfig = rqueueConfig;
  this.rqueueMessageTemplate = rqueueMessageTemplate;
  this.messageMetadataService = messageMetadataService;
}
 
Example 22
Source Project: enode   Source File: EnodeEventStoreAutoConfig.java    License: MIT License 5 votes vote down vote up
@Bean
@ConditionalOnProperty(prefix = "spring.enode", name = "eventstore", havingValue = "mysql")
public MysqlEventStore mysqlEventStore(@Qualifier("enodeMysqlDataSource") DataSource mysqlDataSource, IEventSerializer eventSerializer) {
    MysqlEventStore eventStore = new MysqlEventStore(mysqlDataSource, DBConfiguration.mysql(), eventSerializer);
    vertx.deployVerticle(eventStore, res -> {
    });
    return eventStore;
}
 
Example 23
@Bean(autowireCandidate = false)
Runnable testBean(Map<String, Runnable> testBeans,
		@Qualifier("systemProperties") Map<String, String> sysprops,
		@Qualifier("systemEnvironment") Map<String, String> sysenv) {
	this.testBeans = testBeans;
	assertSame(env.getSystemProperties(), sysprops);
	assertSame(env.getSystemEnvironment(), sysenv);
	return () -> {};
}
 
Example 24
Source Project: cubeai   Source File: UaaSignatureVerifierClient.java    License: Apache License 2.0 5 votes vote down vote up
public UaaSignatureVerifierClient(DiscoveryClient discoveryClient, @Qualifier("loadBalancedRestTemplate") RestTemplate restTemplate,
                              OAuth2Properties oAuth2Properties) {
    this.restTemplate = restTemplate;
    this.oAuth2Properties = oAuth2Properties;
    // Load available UAA servers
    discoveryClient.getServices();
}
 
Example 25
Source Project: cubeai   Source File: UaaSignatureVerifierClient.java    License: Apache License 2.0 5 votes vote down vote up
public UaaSignatureVerifierClient(DiscoveryClient discoveryClient, @Qualifier("loadBalancedRestTemplate") RestTemplate restTemplate,
                              OAuth2Properties oAuth2Properties) {
    this.restTemplate = restTemplate;
    this.oAuth2Properties = oAuth2Properties;
    // Load available UAA servers
    discoveryClient.getServices();
}
 
Example 26
Source Project: springboot-link-admin   Source File: DataSourceConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean(name = "baseDataSource")
@Qualifier("baseDataSource")
@ConfigurationProperties(prefix = "spring.datasource.base")
@Primary
public DataSource primaryDataSource() {
	return DataSourceBuilder.create().build();
}
 
Example 27
@Autowired
public ConstructorValueTestBean(
		@Value("XXX#{tb0.name}YYY#{mySpecialAttr}ZZZ") String name,
		@Value("#{mySpecialAttr}") int age,
		@Qualifier("original") TestBean tb,
		@Value("${code} #{systemProperties.country}") String country) {
	this.name = name;
	this.age = age;
	this.country = country;
	this.tb = tb;
}
 
Example 28
Source Project: light-reading-cloud   Source File: MybatisConfig.java    License: MIT License 5 votes vote down vote up
/** 工厂配置 */
@Bean
public SqlSessionFactory sqlSessionFactoryBean(@Qualifier("accountCenterDataSource") DataSource dataSource) throws Exception {
    // 设置数据源
    SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
    factory.setDataSource(dataSource);

    // 添加XML映射
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    factory.setMapperLocations(resolver.getResources(MAPPER_LOCATIONS));

    //添加插件
    factory.setPlugins(new Interceptor[]{ this.getPageHelper() });
    return factory.getObject();
}
 
Example 29
Source Project: cubeai   Source File: UaaSignatureVerifierClient.java    License: Apache License 2.0 5 votes vote down vote up
public UaaSignatureVerifierClient(DiscoveryClient discoveryClient, @Qualifier("loadBalancedRestTemplate") RestTemplate restTemplate,
                              OAuth2Properties oAuth2Properties) {
    this.restTemplate = restTemplate;
    this.oAuth2Properties = oAuth2Properties;
    // Load available UAA servers
    discoveryClient.getServices();
}
 
Example 30
Source Project: springboot-learn   Source File: MasterDataSourcesConfig.java    License: MIT License 5 votes vote down vote up
@Bean(name = "masterSqlSessionFactory")
@Primary
public SqlSessionFactory masterSqlSessionFactory(@Qualifier("masterDataSource") DataSource dataSource) throws Exception {
    final SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();
    sessionFactoryBean.setDataSource(dataSource);
    sessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(MAPPER_LOCAL));
    return sessionFactoryBean.getObject();
}