Comments (5)
Hi @saksham-kakkar,
public class EmbeddedCassandraInitializer implements InitializingBean {
private final CqlSession session;
public EmbeddedCassandraInitializer(CqlSession session) {
this.session = session;
}
@Override
public void afterPropertiesSet() throws Exception {
// initialize cassandra
CqlScript.ofClassPath("schema.cql").forEachStatement(this.session::execute);
}
}
public class EmbeddedCassandraInitializerPostProcessor implements BeanPostProcessor, Ordered, BeanFactoryAware {
private BeanFactory beanFactory;
@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
this.beanFactory = beanFactory;
}
@Override
public int getOrder() {
return Ordered.HIGHEST_PRECEDENCE + 1;
}
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof Cassandra) {
this.beanFactory.getBean(EmbeddedCassandraInitializer.class);
}
return bean;
}
}
@Configuration(proxyBeanMethods = false)
@Import(EmbeddedCassandraInitializer.class)
public class CassandraConfiguration {
@Bean
public static EmbeddedCassandraInitializerPostProcessor embeddedCassandraInitializerPostProcessor() {
return new EmbeddedCassandraInitializerPostProcessor();
}
}
from embedded-cassandra-spring-boot-starter.
Another way, you can register:
@Configuration(proxyBeanMethods = false)
static class CqlSessionFactoryBeanConfiguration {
@Bean
CqlSessionFactoryBean cqlSessionFactoryBean() {
CqlSessionFactoryBean cqlSessionFactoryBean = new CqlSessionFactoryBean();
cqlSessionFactoryBean.setLocalDatacenter("datacenter1");
cqlSessionFactoryBean.setKeyspaceSpecifications();
cqlSessionFactoryBean.setKeyspaceStartupScripts();
cqlSessionFactoryBean.setKeyspaceShutdownScripts();
return cqlSessionFactoryBean;
}
}
but bear in mind, this will replace the auto-configured CqlSession
.
from embedded-cassandra-spring-boot-starter.
Thanks for the quick response. I'll check these out.
from embedded-cassandra-spring-boot-starter.
Hi @nosan
Failed to instantiate [com.datastax.oss.driver.api.core.CqlSession]: Factory method 'cassandraSession' threw exception; nested exception is com.datastax.oss.driver.api.core.InvalidKeyspaceException: Invalid keyspace
How can I define keyspace before CqlSession init?
from embedded-cassandra-spring-boot-starter.
Hi @mwojtaczka
Sorry, I have not seen your message, looks like somehow I just missed it :(
Unfortunately, there is no easy way to do it.
You can either use CqlSessionFactoryBean
which supports keyspace creation or use the separate CqlSession
to create a keyspace.
from embedded-cassandra-spring-boot-starter.
Related Issues (8)
- Spring Boot Unit Test Example with embedded Cassandra DB? HOT 5
- embedded-cassandra on Java 17 HOT 2
- How do I set up authentication? HOT 2
- I want to set the Cassandra timezone to UTC + 9 or KST. HOT 15
- Java 17 with Cassandra running on java 8 HOT 9
- Spring Boot test is failing with NoClassDefFoundError of StringUtils HOT 30
- Webflux problem HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from embedded-cassandra-spring-boot-starter.