Add Cassandra support

Add auto-configuration support and health checks for Cassandra and
Spring Data Cassandra.

Fixes gh-2064
Closes gh-2214
This commit is contained in:
Julien Dubois
2014-12-22 11:06:37 +01:00
committed by Phillip Webb
parent 49fab4a60f
commit c401330901
32 changed files with 1417 additions and 4 deletions

View File

@@ -340,6 +340,22 @@ content into your application; rather pick only the properties that you need.
# DAO ({sc-spring-boot-autoconfigure}/dao/PersistenceExceptionTranslationAutoConfiguration.{sc-ext}[PersistenceExceptionTranslationAutoConfiguration])
spring.dao.exceptiontranslation.enabled=true
# CASSANDRA ({sc-spring-boot-autoconfigure}/cassandra/CassandraProperties.{sc-ext}[CassandraProperties])
spring.data.cassandra.cluster-name= # the cluster name
spring.data.cassandra.contact-points=localhost # comma-list of cluster node addresses
spring.data.cassandra.keyspace-name= # the keyspace name
spring.data.cassandra.port= # the connection port
spring.data.cassandra.compression= # compression method (none/snappy/lz4)
spring.data.cassandra.loadbalancing-policy= # class name for a LoadBalancingPolicy
spring.data.cassandra.consistency-level= # consistency level (any/one/two/three/quorum/all...)
spring.data.cassandra.serial-consistency-level= # serial consistency level (any/one/two/three/quorum/all...)
spring.data.cassandra.fetch-size=
spring.data.cassandra.reconnection-policy= # class name for a ReconnectionPolicy
spring.data.cassandra.retry-policy= # class name for a RetryPolicy
spring.data.cassandra.connect-timeout-millis= # connect timeout (ms)
spring.data.cassandra.read-timeout-millis= # read timeout (ms)
spring.data.cassandra.ssl=false
# MONGODB ({sc-spring-boot-autoconfigure}/mongo/MongoProperties.{sc-ext}[MongoProperties])
spring.data.mongodb.host= # the db host
spring.data.mongodb.port=27017 # the connection port (defaults to 27107)

View File

@@ -2460,9 +2460,9 @@ http://projects.spring.io/spring-data-redis/[Redis],
http://projects.spring.io/spring-data-gemfire/[Gemfire],
http://projects.spring.io/spring-data-couchbase/[Couchbase] and
http://projects.spring.io/spring-data-cassandra/[Cassandra].
Spring Boot provides auto-configuration for Redis, MongoDB, Elasticsearch, and Solr; you
can make use of the other projects, but you will need to configure them yourself. Refer to
the appropriate reference documentation at
Spring Boot provides auto-configuration for Redis, MongoDB, Elasticsearch, Solr and
Cassandra; you can make use of the other projects, but you will need to configure them
yourself. Refer to the appropriate reference documentation at
http://projects.spring.io/spring-data[projects.spring.io/spring-data].
@@ -2781,6 +2781,63 @@ http://docs.spring.io/spring-data/elasticsearch/docs/[reference documentation].
[[boot-features-cassandra]]
=== Cassandra
http://cassandra.apache.org/[Cassandra] is an open source, distributed database management
system designed to handle large amounts of data across many commodity servers. Spring Boot
offers auto-configuration for Cassandra and abstractions on top of it provided by
https://github.com/spring-projects/spring-data-cassandra[Spring Data Cassandra].
There is a `spring-boot-starter-data-cassandra` '`Starter POM`' for collecting the
dependencies in a convenient way.
[[boot-features-connecting-to-cassandra]]
==== Connecting to Cassandra
You can inject an auto-configured `CassandraTemplate` or a Cassandra `Session`
instance as you would any other Spring Bean. The `spring.data.cassandra.*` properties
can be used to customize the connection. Generally you will to provide `keyspace-name`
and `contact-points` properties:
[source,properties,indent=0]
----
spring.data.cassandra.keyspace-name=mykeyspace
spring.data.cassandra.contact-points=cassandrahost1,cassandrahost2
----
[source,java,indent=0]
----
@Component
public class MyBean {
private CassandraTemplate template;
@Autowired
public MyBean(CassandraTemplate template) {
this.template = template;
}
// ...
}
----
If you add a `@Bean` of your own of type `CassandraTemplate` it will replace the
default.
[[boot-features-spring-data-cassandra-repositories]]
==== Spring Data Cassandra repositories
Spring Data includes basic repository support for Cassandra. Currently this is more
limited than the JPA repositories discussed earlier, and will need to annotate finder
methods with `@Query`.
TIP: For complete details of Spring Data Cassandra, refer to their
http://docs.spring.io/spring-data/cassandra/docs/[reference documentation].
[[boot-features-caching]]
== Caching
The Spring Framework provides support for transparently adding caching to an application.