Add this annotation to an @
Configuration
class to have a bean for each
service bound to the app as well as one for
ApplicationInstanceInfo
added to
the application context.
@Configuration
@CloudScan
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. @CloudScan, in the same
spirit, scans services bound to the app and creates a bean for each. It also creates a bean
of
ApplicationInstanceInfo
class to expose information about the application instance.
Upon service scanning, if there is a unique bean 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;
Similarly, application can have
ApplicationInstanceInfo
injected as follows:
@Autowired ApplicationInstanceInfo applicationInstanceInfo;
Note the difference between @
ServiceScan
and this annotation. While the former only
adds beans for each bound service, the @
CloudScan
annotation also adds a
bean for
ApplicationInstanceInfo
.