我刚开始用cassandra和java以及spring REST库进行实验。
java.lang.NoSuchMethodException: objects.DataSet.<init>()
at java.lang.Class.getConstructor0(Class.java:3082) ~[na:1.8.0_111]
at java.lang.Class.getConstructor(Class.java:1825) ~[na:1.8.0_111]
at com.datastax.driver.mapping.ReflectionUtils.newInstance(ReflectionUtils.java:37) ~[cassandra-driver-mapping-3.1.0.jar:na]
at com.datastax.driver.mapping.EntityMapper.newEntity(EntityMapper.java:62) ~[cassandra-driver-mapping-3.1.0.jar:na]
@RequestMapping(value="/data_sets/{dataSetId}", method=RequestMethod.GET)
public DataSet show(@PathVariable(value="dataSetId") String dataSetId){
Cluster cluster = Cluster.builder().withClusterName("testCluster").addContactPoint("127.0.0.1").build();
Session session = cluster.connect("testks");
MappingManager manager = new MappingManager(session);
Mapper<DataSet> mapper = manager.mapper(DataSet.class);
System.out.println("loading data set ....");
DataSet dataSet = mapper.get(dataSetId);
return dataSet;
}
@Table(keyspace="testks", name="DataSet", caseSensitiveKeyspace=false, caseSensitiveTable=false)
public class DataSet {
@PartitionKey
@Column
String id;
@Column
String name;
public String getName() {
return name;
}
public DataSet setName(String name) {
this.name = name;
return this;
}
public DataSet setId(String id){
this.id = id;
return this;
}
public DataSet(String name){
this.id = UUIDs.timeBased().toString();
this.name = name;
}
这里是pom.xml
<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>Banana</groupId>
<artifactId>Banana</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source />
<target />
</configuration>
</plugin>
</plugins>
</build>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<dependencies>
<!--<dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-cassandra</artifactId>
<version>1.4.4.RELEASE</version> </dependency> -->
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</dependency>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-mapping</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-extras</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>4.2.1.BUILD-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.0.4.RELEASE</version>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.2.0</version>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<repositories>
<repository>
<id>spring-milestone</id>
<name>Spring Maven MILESTONE Repository</name>
<url>http://repo.spring.io/libs-milestone</url>
</repository>
<repository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</repository>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/libs-snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>
哦,我现在明白问题了
您需要添加构造函数
@Table(keyspace="testks", name="DataSet", caseSensitiveKeyspace=false, caseSensitiveTable=false)
public class DataSet {
@PartitionKey
@Column
String id;
@Column
String name;
public Dataset() {
}
public String getName() {
return name;
}
public DataSet setName(String name) {
this.name = name;
return this;
}
public DataSet setId(String id){
this.id = id;
return this;
}
public DataSet(String name){
this.id = UUIDs.timeBased().toString();
this.name = name;
}
}
是否可能在MapStruct中使用不同的映射器?我有这个映射器 是否可以将此实现更改为MapStruct?
我有两个对象,除了date成员外,其他成员都相同。在obj1中,date是java.sql.date,obj2.date是long(纪元)。 我需要编写一个映射器来将obj1映射到obj2。这就是我试图做的: 但是mapperImpl只有自己的日期转换实现: 我得到了: 这种转换的正确方式是什么?
我想用Kotlin中的Mapstruct将实体映射到带有嵌套DTO的DTO。 在Java中,这是这样的:。 应该如何使用Kotlin实现它?
问题内容: 我已经读过我可以创建一个实现,将抛出的应用程序异常映射到对象。 我创建了一个简单的示例,如果在保留对象时电话长度大于20个字符,则会引发异常。我期望将异常映射到HTTP 400(错误请求)响应;但是,我收到HTTP 500(内部服务器错误),但有以下异常: 我想念什么?任何意见是极大的赞赏。 异常映射器: 异常类: 实体类: 服务: 问题答案: InvalidDataException
我得到了,我不知道我的错误在哪里。 错误出现在函数中。代码是: 控制器。JAVA 应用上下文如下: 这里有一个错误: [11/07/14 11.19.33:848 CEST]000000 4F servlet电子商务。国际商用机器公司ws。网络容器。servlet。ServletWrapper服务SRVE0068E:在uno dei metodi di servlet dispatcher nel