Issue
I m developing spring cloud project based microservice.(packaging maven)I m using cassandra on docker image in project. I m taking error in CassandraConfiguration. I imported "import org.springframework.data.cassandra.config.CassandraClusterFactoryBean;" in CassandraConfiguration ,but I took error. Error Message in intellij idea. I tried to run this project on eclipse. I got an error again. Thank you!
java: cannot find symbol
symbol: class Cassandra Cluster Factory Bean
location: class com.accountservice.springcloudmicroserviceaccount.Configuration.CassandraConfiguration
import org.springframework.data.cassandra.config.CassandraClusterFactoryBean;
and public CassandraClusterFactoryBean cluster(){
CassandraClusterFactoryBean cluster=super.cluster();
cluster.setUsername(username);
cluster.setPassword(password);
return cluster;
}
I tried to do something pom.xml. I searched solve on this website, but I got an error again. pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.accountservice</groupId>
<artifactId>springcloudmicroserviceaccount</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springcloudmicroserviceaccount</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-cassandra</artifactId>
</dependency>
<dependency>
<groupId>com.codahale.metrics</groupId>
<artifactId>metrics-core</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>19</source>
<target>19</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Solution
CassandraClusterFactoryBean
was removed in 2019 with the migration to Cassandra driver 4. All details can be found in the original pull request on GitHub: https://github.com/spring-projects/spring-data-cassandra/pull/167
Breaking changes:
Removal of types (without replacement):
- […]
- CassandraCqlClusterFactoryBean
- […]
Configuration summary
Driver 4 merges Cluster and Session objects into a single CqlSession object, therefore all Cluster-related API was removed. The Configuration was revised in large parts by removing most configuration items that were moved into DriverConfigLoader that is mostly file-based. This means that SocketOptions, AddressTranslator and many more options are configured now through other means.
Further information:
- https://docs.datastax.com/en/developer/java-driver/4.3/
- https://docs.datastax.com/en/developer/java-driver/4.3/upgrade_guide/
[emphasis mine]
More information quoted from the upgrade guide:
Cluster
does not exist anymore; the session is now the main component, initialized in a single step:CqlSession session = CqlSession.builder().build(); session.execute("...");
Answered By - knittl
Answer Checked By - Gilberto Lyons (JavaFixing Admin)