Guest User

Untitled

a guest
Mar 10th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. One session connecting to primary Keysapce as configured in spring.data.cassandra.keyspace-name
  2. One session connecting to keyspaceB
  3.  
  4. @Value("${spring.data.cassandra.keyspace-name}")
  5. private String primaryKeysapce;
  6.  
  7. @Value("${item.keysapce.b:keyspaceB}")
  8. private String keyspaceB;
  9.  
  10.  
  11. @Override
  12. @Primary
  13. @Bean
  14. public CassandraSessionFactoryBean session() throws ClassNotFoundException {
  15. return super.session();
  16. }
  17.  
  18. @Bean("cassandraOperations")
  19. @Primary
  20. public CassandraOperations cassandraOperations() throws ClassNotFoundException {
  21. return new CassandraTemplate(session().getObject(), cassandraConverter());
  22. }
  23.  
  24. @Bean("sessionB")
  25. public CassandraSessionFactoryBean sessionB() throws ClassNotFoundException {
  26. CassandraSessionFactoryBean session = super.session();
  27. session.setKeyspaceName(keyspaceB);
  28. return session;
  29. }
  30.  
  31. @Bean("cassandraOperationsB")
  32. public CassandraOperations cassandraOperationsB() throws ClassNotFoundException {
  33. return new CassandraTemplate(sessionB().getObject(), cassandraConverter());
  34. }
  35.  
  36.  
  37. @Override
  38. protected String getKeyspaceName() {
  39. return primaryKeysapce;
  40. }
  41.  
  42. spring.data.cassandra.keyspace-name = primary_keysapce
  43. spring.data.cassandra.username = xyz
  44. spring.data.cassandra.password = abcd
  45. spring.data.cassandra.contact-points=myhost.company.com
  46.  
  47. @SpringBootApplication
  48. @EnableAutoConfiguration
  49. public class DemoApplication implements CommandLineRunner {
  50.  
  51.  
  52. @Resource(name = "cassandraOperationsB")
  53. CassandraOperations cassandraOperationsB;
  54.  
  55. // hall point to primary one as per spring properties
  56. @Autowired
  57. CassandraOperations cassandraOperations;
  58.  
  59. public static void main(String[] args) {
  60. SpringApplication.run(DemoApplication.class, args);
  61. }
  62.  
  63. }
Add Comment
Please, Sign In to add comment