-
Notifications
You must be signed in to change notification settings - Fork 182
Spring
To reference cloud based services within Spring use the new cloud namespace. The cloud namespace provides support for defining beans backed by services.
<cloud:data-source/>
<cloud:redis-connection-factory/>
<cloud:mongo/>
This style works as long as you have only one service of each type bound to the application.
If you want to bind to specific services (perhaps because you have more than one of a kind of service, for example two MySql services), you need to specify the service-name attribute as follows:
<cloud:data-source service-name="inventory-db"/>
<cloud:data-source service-name="pricing-db"/>
In your Java code, simply add @Autowired dependencies for each bounded service:
@Autowired DataSource dataSource;
@Autowired RedisConnectionFactory redisConnectionFactory;
@Autowired Mongo mongo;
You have access to services without breaking a sweat.
The service name will be used as the bean id by default, but if you would prefer to use a separate value for that, you can specify the 'id' attribute. Regardless of how the id is determined, you can specify the @Qualifier annotation to pick the right bean or even use the XML based configuration. Please check the Spring Framework documentation for more details.
To access the namespace, add the following to your maven pom.xml
<dependency>
<groupId>org.cloudfabric</groupId>
<artifactId>runtime</artifactId>
<version>0.5.0-LD</version>
</dependency>
and the following maven repository location
<repositories>
<repository>
<id>spring-milestone</id>
<url>http://s3.amazonaws.com/private.maven.springsource.com/milestone/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
TBD
The initial set of services offered are
- RDBMS - MySql
- [Redis] (http://redis.io/)
- [MongoDB] (http://www.mongodb.org/)
Spring Framework integration with all of the technologies is discussed below.
Spring has always provided great support for relational databases. Spring's JDBC and ORM support can be used within Cloud Foundry.
A new Spring project, Spring JPA, provides great infrastructure support to further kickstart your development. It will automatically provide implementations of of Repository interfaces including support for custom finder methods. There is also integration wit QueryDSL so that you can write type-safe queries.
The boostrapping of a datasource is the only thing you need to be concerned with.
If you are using Spring's cloud namespace, then in your Spring XML configuration file declare the following element
<cloud:data-source/>
The service name will be used as the bean id by default, but if you would prefer to use a separate value for that, you can specify the 'id' attribute. You can then reference within other Spring XML definitions or within your classes using @Autowired or @Inject annotations.
Part of the umbrella Spring Data project, the Spring Data Key Value provides integration with Redis.
To quote the Redis project home page: "Redis is an advanced key-value store. It is similar to memcached but the dataset is not volatile, and values can be strings, exactly like in memcached, but also lists, sets, and ordered sets. All this data types can be manipulated with atomic operations to push/pop elements, add/remove elements, perform server side union, intersection, difference between sets, and so forth. Redis supports different kind of sorting abilities."
Spring Redis integration provides easy configuration and access to Redis from Spring application. Offers both low-level and high-level abstraction for interacting with the store, freeing the user from infrastructural concerns.
The sample application RetwisJ is running on Cloud Foundry and showcases various Spring Redis features. Please read the RetwisJ documentation and look at the source code
usage/setup description and links to Spring Data Mongo docs
TBD