@Retention(value=RUNTIME) @Target(value=TYPE) @Documented @Import(value=ServiceScanConfiguration.class) public @interface ServiceScan
Configuration
class to have the services bound
to the app scanned and bean for each one added to the application context:
@Configuration @ServiceScan public class CloudConfiguration { // may (optionally) extend AbstractCloudConfiguration }This annotation is similar to @ComponentScan in Spring, which scans for classes with the @Component classes and creates a bean for each. @ServiceScan, in the same spirit, scans services bound to the app and creates a bean for each. Upon service scanning, if there is a unique bean of for service type, you can inject it using the following code (shows Redis, but the same scheme works for all services):
@Autowired RedisConnectionFactory redisConnectionFactory;If there are more than one services of a type, you can use the @Qualifier annotation as in the following code:
@Autowired @Qualifier("service-name1") RedisConnectionFactory redisConnectionFactory; @Autowired @Qualifier("service-name2") RedisConnectionFactory redisConnectionFactory;
Copyright © 2015 Pivotal Software, Inc.. All rights reserved.