gpt4 book ai didi

configuration - Spring Boot + cassandra

转载 作者:行者123 更新时间:2023-12-04 19:01:39 25 4
gpt4 key购买 nike

我开始学习 cassandra,我想连接 Spring boot 框架,但我遇到了很多错误和误解。我第一次花了一整天时间才明​​白我必须使用 Cassandra 2.x.x 版本而不是 3.x.x,因为 Spring 数据 Cassandra 不支持它。所以我删除了 Maven 中的任何版本并且它运行了!第二次我和上次完全一样,但我又犯了一些错误,是幸运还是什么?我什么都看不懂!请帮我澄清一下。

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.libra</groupId>
<artifactId>libra</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>libra</name>
<description>Demo project for Spring Boot</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-cassandra</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</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>
</plugins>
</build>


</project>

配置 Cassandra
package com.libra.configs;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.cassandra.config.SchemaAction;
import org.springframework.data.cassandra.config.java.AbstractCassandraConfiguration;
import org.springframework.data.cassandra.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.core.CassandraOperations;
import org.springframework.data.cassandra.core.CassandraTemplate;
import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;

@Configuration
@EnableCassandraRepositories("com.libra.domain.repositories")
public class CassandraConfig extends AbstractCassandraConfiguration{

private static final String KEYSPACE_NAME = "libra";
private static final String CONTACT_POINTS = "127.0.0.1";
private static final int PORT = 9042;

@Override
protected String getKeyspaceName() {

return KEYSPACE_NAME;
}

@Override
protected String getContactPoints() {
return CONTACT_POINTS;
}

@Override
protected int getPort() {
return PORT;
}

@Override
public SchemaAction getSchemaAction() {
return SchemaAction.RECREATE_DROP_UNUSED;
}

@Bean
public CassandraOperations operations() throws Exception {

return new CassandraTemplate(session().getObject(), new MappingCassandraConverter(new BasicCassandraMappingContext()));
}
}

该表是:
package com.libra.domain;

import org.springframework.data.cassandra.mapping.PrimaryKey;
import org.springframework.data.cassandra.mapping.Table;

import java.util.UUID;

@Table
public class Book {

@PrimaryKey
private UUID id;

private String name;

private String author;

private int count;

public Book(){

}

public Book(UUID id, String name, String author, int count){
this.id = id;
this.name = name;
this.author = author;
this.count = count;
}

public String getAuthor() {
return author;
}

public void setAuthor(String author) {
this.author = author;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public UUID getId() {
return id;
}

public void setId(UUID id) {
this.id = id;
}

public int getCount() {
return count;
}

public void setCount(int count) {
this.count = count;
}
}

我尝试从命令行运行:
package com.libra;

import com.datastax.driver.core.utils.UUIDs;
import com.libra.domain.Book;
import com.libra.services.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class LibraApplication implements CommandLineRunner {

public static void main(String[] args) {
SpringApplication.run(LibraApplication.class, args);
}

@Autowired
private BookService bookService;

@Override
public void run(String... args) throws Exception {
bookService.saveBook(new Book(UUIDs.timeBased(),"name","author",3));

}
}

错误:
2016-04-02 22:51:39.897  INFO 5388 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2016-04-02 22:51:43.080 ERROR 5388 --- [ main] o.s.boot.SpringApplication : Application startup failed

java.lang.IllegalStateException: Failed to execute CommandLineRunner
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:809) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:790) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:777) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at com.libra.LibraApplication.main(LibraApplication.java:15) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_65]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_65]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_65]
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_65]
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) [idea_rt.jar:na]
Caused by: org.springframework.cassandra.support.exception.CassandraInvalidQueryException: unconfigured table book; nested exception is com.datastax.driver.core.exceptions.InvalidQueryException: unconfigured table book
at org.springframework.cassandra.support.CassandraExceptionTranslator.translateExceptionIfPossible(CassandraExceptionTranslator.java:116) ~[spring-cql-1.3.4.RELEASE.jar:na]
at org.springframework.cassandra.config.CassandraCqlSessionFactoryBean.translateExceptionIfPossible(CassandraCqlSessionFactoryBean.java:74) ~[spring-cql-1.3.4.RELEASE.jar:na]
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59) ~[spring-tx-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213) ~[spring-tx-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147) ~[spring-tx-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208) ~[spring-aop-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at com.sun.proxy.$Proxy57.save(Unknown Source) ~[na:na]
at com.libra.services.BookService.saveBook(BookService.java:25) ~[classes/:na]
at com.libra.LibraApplication.run(LibraApplication.java:23) [classes/:na]
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:806) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
... 11 common frames omitted
Caused by: com.datastax.driver.core.exceptions.InvalidQueryException: unconfigured table book
at com.datastax.driver.core.exceptions.InvalidQueryException.copy(InvalidQueryException.java:50) ~[cassandra-driver-core-2.1.9.jar:na]
at com.datastax.driver.core.DriverThrowables.propagateCause(DriverThrowables.java:37) ~[cassandra-driver-core-2.1.9.jar:na]
at com.datastax.driver.core.DefaultResultSetFuture.getUninterruptibly(DefaultResultSetFuture.java:214) ~[cassandra-driver-core-2.1.9.jar:na]
at com.datastax.driver.core.AbstractSession.execute(AbstractSession.java:52) ~[cassandra-driver-core-2.1.9.jar:na]
at org.springframework.cassandra.core.CqlTemplate$12.doInSession(CqlTemplate.java:503) ~[spring-cql-1.3.4.RELEASE.jar:na]
at org.springframework.cassandra.core.CqlTemplate$12.doInSession(CqlTemplate.java:494) ~[spring-cql-1.3.4.RELEASE.jar:na]
at org.springframework.cassandra.core.CqlTemplate.doExecute(CqlTemplate.java:471) ~[spring-cql-1.3.4.RELEASE.jar:na]
at org.springframework.cassandra.core.CqlTemplate.doExecute(CqlTemplate.java:494) ~[spring-cql-1.3.4.RELEASE.jar:na]
at org.springframework.cassandra.core.CqlTemplate.execute(CqlTemplate.java:1209) ~[spring-cql-1.3.4.RELEASE.jar:na]
at org.springframework.data.cassandra.core.CassandraTemplate.doInsert(CassandraTemplate.java:642) ~[spring-data-cassandra-1.3.4.RELEASE.jar:na]
at org.springframework.data.cassandra.core.CassandraTemplate.insert(CassandraTemplate.java:237) ~[spring-data-cassandra-1.3.4.RELEASE.jar:na]
at org.springframework.data.cassandra.core.CassandraTemplate.insert(CassandraTemplate.java:232) ~[spring-data-cassandra-1.3.4.RELEASE.jar:na]
at org.springframework.data.cassandra.repository.support.SimpleCassandraRepository.save(SimpleCassandraRepository.java:59) ~[spring-data-cassandra-1.3.4.RELEASE.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_65]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_65]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_65]
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_65]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:483) ~[spring-data-commons-1.11.4.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:468) ~[spring-data-commons-1.11.4.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:440) ~[spring-data-commons-1.11.4.RELEASE.jar:na]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61) ~[spring-data-commons-1.11.4.RELEASE.jar:na]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208) ~[spring-aop-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at com.sun.proxy.$Proxy57.save(Unknown Source) ~[na:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_65]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_65]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_65]
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_65]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302) ~[spring-aop-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) ~[spring-aop-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136) ~[spring-tx-4.2.5.RELEASE.jar:4.2.5.RELEASE]
... 17 common frames omitted
Caused by: com.datastax.driver.core.exceptions.InvalidQueryException: unconfigured table book
at com.datastax.driver.core.Responses$Error.asException(Responses.java:102) ~[cassandra-driver-core-2.1.9.jar:na]
at com.datastax.driver.core.DefaultResultSetFuture.onSet(DefaultResultSetFuture.java:149) ~[cassandra-driver-core-2.1.9.jar:na]
at com.datastax.driver.core.RequestHandler.setFinalResult(RequestHandler.java:183) ~[cassandra-driver-core-2.1.9.jar:na]
at com.datastax.driver.core.RequestHandler.access$2300(RequestHandler.java:44) ~[cassandra-driver-core-2.1.9.jar:na]
at com.datastax.driver.core.RequestHandler$SpeculativeExecution.setFinalResult(RequestHandler.java:751) ~[cassandra-driver-core-2.1.9.jar:na]
at com.datastax.driver.core.RequestHandler$SpeculativeExecution.onSet(RequestHandler.java:573) ~[cassandra-driver-core-2.1.9.jar:na]
at com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:1009) ~[cassandra-driver-core-2.1.9.jar:na]
at com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:932) ~[cassandra-driver-core-2.1.9.jar:na]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) ~[netty-transport-4.0.27.Final.jar:4.0.27.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:339) ~[netty-transport-4.0.27.Final.jar:4.0.27.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:324) ~[netty-transport-4.0.27.Final.jar:4.0.27.Final]
at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:254) ~[netty-handler-4.0.27.Final.jar:4.0.27.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:339) ~[netty-transport-4.0.27.Final.jar:4.0.27.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:324) ~[netty-transport-4.0.27.Final.jar:4.0.27.Final]
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) ~[netty-codec-4.0.27.Final.jar:4.0.27.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:339) ~[netty-transport-4.0.27.Final.jar:4.0.27.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:324) ~[netty-transport-4.0.27.Final.jar:4.0.27.Final]
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:242) ~[netty-codec-4.0.27.Final.jar:4.0.27.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:339) ~[netty-transport-4.0.27.Final.jar:4.0.27.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:324) ~[netty-transport-4.0.27.Final.jar:4.0.27.Final]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:847) ~[netty-transport-4.0.27.Final.jar:4.0.27.Final]
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131) ~[netty-transport-4.0.27.Final.jar:4.0.27.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511) ~[netty-transport-4.0.27.Final.jar:4.0.27.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468) ~[netty-transport-4.0.27.Final.jar:4.0.27.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382) ~[netty-transport-4.0.27.Final.jar:4.0.27.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354) ~[netty-transport-4.0.27.Final.jar:4.0.27.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:111) ~[netty-common-4.0.27.Final.jar:4.0.27.Final]
at java.lang.Thread.run(Thread.java:745) ~[na:1.8.0_65]

2016-04-02 22:51:43.086 INFO 5388 --- [ main] .b.l.ClasspathLoggingApplicationListener : Application failed to start with classpath: [file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/charsets.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/deploy.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/ext/access-bridge-64.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/ext/cldrdata.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/ext/dnsns.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/ext/jaccess.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/ext/jfxrt.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/ext/localedata.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/ext/nashorn.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/ext/sunec.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/ext/sunjce_provider.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/ext/sunmscapi.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/ext/sunpkcs11.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/ext/zipfs.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/javaws.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/jce.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/jfr.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/jfxswt.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/jsse.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/management-agent.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/plugin.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/resources.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/rt.jar, file:/C:/Users/LastBreath/Desktop/libra/target/classes/, file:/C:/Users/LastBreath/.m2/repository/org/springframework/boot/spring-boot-starter-data-cassandra/1.3.3.RELEASE/spring-boot-starter-data-cassandra-1.3.3.RELEASE.jar, file:/C:/Users/LastBreath/.m2/repository/org/springframework/boot/spring-boot-starter/1.3.3.RELEASE/spring-boot-starter-1.3.3.RELEASE.jar, file:/C:/Users/LastBreath/.m2/repository/org/springframework/boot/spring-boot/1.3.3.RELEASE/spring-boot-1.3.3.RELEASE.jar, file:/C:/Users/LastBreath/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/1.3.3.RELEASE/spring-boot-autoconfigure-1.3.3.RELEASE.jar, file:/C:/Users/LastBreath/.m2/repository/org/springframework/boot/spring-boot-starter-logging/1.3.3.RELEASE/spring-boot-starter-logging-1.3.3.RELEASE.jar, file:/C:/Users/LastBreath/.m2/repository/ch/qos/logback/logback-classic/1.1.5/logback-classic-1.1.5.jar, file:/C:/Users/LastBreath/.m2/repository/ch/qos/logback/logback-core/1.1.5/logback-core-1.1.5.jar, file:/C:/Users/LastBreath/.m2/repository/org/slf4j/jul-to-slf4j/1.7.16/jul-to-slf4j-1.7.16.jar, file:/C:/Users/LastBreath/.m2/repository/org/slf4j/log4j-over-slf4j/1.7.16/log4j-over-slf4j-1.7.16.jar, file:/C:/Users/LastBreath/.m2/repository/org/yaml/snakeyaml/1.16/snakeyaml-1.16.jar, file:/C:/Users/LastBreath/.m2/repository/org/springframework/spring-tx/4.2.5.RELEASE/spring-tx-4.2.5.RELEASE.jar, file:/C:/Users/LastBreath/.m2/repository/org/springframework/spring-beans/4.2.5.RELEASE/spring-beans-4.2.5.RELEASE.jar, file:/C:/Users/LastBreath/.m2/repository/org/springframework/data/spring-data-cassandra/1.3.4.RELEASE/spring-data-cassandra-1.3.4.RELEASE.jar, file:/C:/Users/LastBreath/.m2/repository/org/springframework/data/spring-cql/1.3.4.RELEASE/spring-cql-1.3.4.RELEASE.jar, file:/C:/Users/LastBreath/.m2/repository/com/google/guava/guava/18.0/guava-18.0.jar, file:/C:/Users/LastBreath/.m2/repository/org/springframework/spring-expression/4.2.5.RELEASE/spring-expression-4.2.5.RELEASE.jar, file:/C:/Users/LastBreath/.m2/repository/org/springframework/data/spring-data-commons/1.11.4.RELEASE/spring-data-commons-1.11.4.RELEASE.jar, file:/C:/Users/LastBreath/.m2/repository/com/datastax/cassandra/cassandra-driver-dse/2.1.9/cassandra-driver-dse-2.1.9.jar, file:/C:/Users/LastBreath/.m2/repository/com/datastax/cassandra/cassandra-driver-core/2.1.9/cassandra-driver-core-2.1.9.jar, file:/C:/Users/LastBreath/.m2/repository/io/netty/netty-handler/4.0.27.Final/netty-handler-4.0.27.Final.jar, file:/C:/Users/LastBreath/.m2/repository/io/netty/netty-buffer/4.0.27.Final/netty-buffer-4.0.27.Final.jar, file:/C:/Users/LastBreath/.m2/repository/io/netty/netty-common/4.0.27.Final/netty-common-4.0.27.Final.jar, file:/C:/Users/LastBreath/.m2/repository/io/netty/netty-transport/4.0.27.Final/netty-transport-4.0.27.Final.jar, file:/C:/Users/LastBreath/.m2/repository/io/netty/netty-codec/4.0.27.Final/netty-codec-4.0.27.Final.jar, file:/C:/Users/LastBreath/.m2/repository/com/codahale/metrics/metrics-core/3.0.2/metrics-core-3.0.2.jar, file:/C:/Users/LastBreath/.m2/repository/org/slf4j/slf4j-api/1.7.16/slf4j-api-1.7.16.jar, file:/C:/Users/LastBreath/.m2/repository/org/slf4j/jcl-over-slf4j/1.7.16/jcl-over-slf4j-1.7.16.jar, file:/C:/Users/LastBreath/.m2/repository/org/springframework/boot/spring-boot-starter-jersey/1.3.3.RELEASE/spring-boot-starter-jersey-1.3.3.RELEASE.jar, file:/C:/Users/LastBreath/.m2/repository/org/springframework/boot/spring-boot-starter-tomcat/1.3.3.RELEASE/spring-boot-starter-tomcat-1.3.3.RELEASE.jar, file:/C:/Users/LastBreath/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/8.0.32/tomcat-embed-core-8.0.32.jar, file:/C:/Users/LastBreath/.m2/repository/org/apache/tomcat/embed/tomcat-embed-el/8.0.32/tomcat-embed-el-8.0.32.jar, file:/C:/Users/LastBreath/.m2/repository/org/apache/tomcat/embed/tomcat-embed-logging-juli/8.0.32/tomcat-embed-logging-juli-8.0.32.jar, file:/C:/Users/LastBreath/.m2/repository/org/apache/tomcat/embed/tomcat-embed-websocket/8.0.32/tomcat-embed-websocket-8.0.32.jar, file:/C:/Users/LastBreath/.m2/repository/org/springframework/boot/spring-boot-starter-validation/1.3.3.RELEASE/spring-boot-starter-validation-1.3.3.RELEASE.jar, file:/C:/Users/LastBreath/.m2/repository/org/hibernate/hibernate-validator/5.2.4.Final/hibernate-validator-5.om/fasterxml/jackson/jaxrs/jackson-jaxrs-json-provider/2.6.5/jackson-jaxrs-json-provider-2.6.5.jar, file:/C:/Users/LastBreath/.m2/repository/com/fasterxml/jackson/module/jackson-module-jaxb-annotations/2.6.5/jackson-module-jaxb-annotations-2.6.5.jar, file:/C:/Users/LastBreath/.m2/repository/org/springframework/boot/spring-boot-starter-web/1.3.3.RELEASE/spring-boot-starter-web-1.3.3.RELEASE.jar, file:/C:/Users/LastBreath/.m2/repository/org/springframework/spring-webmvc/4.2.5.RELEASE/spring-webmvc-4.2.5.RELEASE.jar, file:/C:/Users/LastBreath/.m2/repository/org/springframework/spring-core/4.2.5.RELEASE/spring-core-4.2.5.RELEASE.jar, file:/C:/Program%20Files%20(x86)/JetBrains/IntelliJ%20IDEA%2015.0.2/lib/idea_rt.jar]
2016-04-02 22:51:43.090 INFO 5388 --- [ main] utoConfigurationReportLoggingInitializer :

Error starting ApplicationContext. To display the auto-configuration report enable debug logging (start with --debug)


2016-04-02 22:51:43.090 INFO 5388 --- [ main] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6cc7b4de: startup date [Sat Apr 02 22:51:30 MSK 2016]; root of context hierarchy
2016-04-02 22:51:43.092 INFO 5388 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown

Process finished with exit code 1

最佳答案

这里有两个问题结合在一起。

  • Spring Data Cassandra 需要先了解实体,然后才能在 Cassandra 中创建表。这是在创建 Session 时完成的。 .
    Spring 扫描使用 @Persistent 注释的实体或 @Table并使用 com.libra.configs作为基础包。这是因为 AbstractCassandraConfiguration.getEntityBasePackages默认为子类的包,CassandraConfig在你的情况下。
    覆盖 getEntityBasePackagesCassandraConfig并返回 com.libra.domain所以实体将从不同的基础包中扫描。
    public class CassandraConfig extends AbstractCassandraConfiguration {

    // …

    @Override
    public String[] getEntityBasePackages() {
    return new String[]{"com.libra.domain"};
    }

    // …
    }
  • Spring Boot 通过使用 properties 配置应用程序来支持 Cassandra ,但它缺少 SchemaAction选项。但是,我们有一个 Github ticket跟踪此问题。

  • HTH,马克

    关于configuration - Spring Boot + cassandra,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36378350/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com