java - Multiple keyspace support for spring-data-cassandra repositories? -


does spring data cassandra support multiple keyspace repositories in same application context? setting cassandra spring data configuration using following javaconfig class

@configuration @enablecassandrarepositories(basepackages = "com.blah.repository") public class cassandraconfig extends abstractcassandraconfiguration {  @override public string getkeyspacename() {     return "keyspace1"; } 

i tried creating second configuration class after moving repository classes different package.

@configuration @enablecassandrarepositories(basepackages = "com.blah.secondrepository") public class secondcassandraconfig extends abstractcassandraconfiguration {  @override public string getkeyspacename() {     return "keyspace2"; } 

however in case first set if repositories fail configured column family entities not found in keyspace. think looking column family in second keyspace.

does spring-data-cassandra support multiple keyspace repositories? place found reference multiple keyspaces here. not explain if can done repositories?

you need override both sessionfactory , template

sample:

1) application.yml

 spring:   data:     cassandra:       test1:         keyspace-name: test1_keyspace         contact-points: localhost       test2:         keyspace-name: test2_keyspace         contact-points: localhost 

2) base config class

public abstract class cassandrabaseconfig extends abstractcassandraconfiguration{     protected string contactpoints;     protected string keyspacename;      public string getcontactpoints() {         return contactpoints;     }     public void setcontactpoints(string contactpoints) {         this.contactpoints = contactpoints;     }      public void setkeyspacename(string keyspacename) {         this.keyspacename = keyspacename;     }     @override     protected string getkeyspacename() {         return keyspacename;     } } 

3) config implementation test1

package com.sample.repo.test1;  @configuration @configurationproperties("spring.data.cassandra.test1") @enablecassandrarepositories(         basepackages = "com.sample.repo.test1",         cassandratemplateref = "test1template" ) public class test1config extends cassandrabaseconfig {      @override     @primary     @bean(name = "test1template")     public cassandraadminoperations cassandratemplate() throws exception {         return new cassandraadmintemplate(session().getobject(), cassandraconverter());     }      @override     @bean(name = "test1session")     public cassandrasessionfactorybean session() throws exception {          cassandrasessionfactorybean session = new cassandrasessionfactorybean();          session.setcluster(cluster().getobject());         session.setconverter(cassandraconverter());         session.setkeyspacename(getkeyspacename());         session.setschemaaction(getschemaaction());         session.setstartupscripts(getstartupscripts());         session.setshutdownscripts(getshutdownscripts());          return session;     } } 

4) same test2, use different package package com.sample.repo.test2;

5) place repo each keyspace in dedicated package i.e.

package com.sample.repo.test1;  @repository public interface repositoryfortest1 extends cassandrarepository<myentity> { // .... }   package com.sample.repo.test2;  @repository public interface repositoryfortest2 extends cassandrarepository<myentity> { // .... } 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -