Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法实例化目标[subclassDTO]的实例。确保[subclassDTO]具有非私有的无参数构造函数_Java_Spring Boot_Inheritance_Dto_Modelmapper - Fatal编程技术网

Java 无法实例化目标[subclassDTO]的实例。确保[subclassDTO]具有非私有的无参数构造函数

Java 无法实例化目标[subclassDTO]的实例。确保[subclassDTO]具有非私有的无参数构造函数,java,spring-boot,inheritance,dto,modelmapper,Java,Spring Boot,Inheritance,Dto,Modelmapper,我正在开发一个Springboot应用程序,它公开了一些端点,这些端点不返回原始实体,但返回了它们的DTO。为了映射我正在使用的所有实体,我使用“org.modelmapper”版本:0.7.4和ProjectLombok来避免实现getter、setter和其他一些实用程序 在我必须映射实体上的子类列表之前,一切都很顺利。源实体如下所示(我删除了一些属性和hibernate注释,因为它们在示例中不是必需的): package com.pfi.repository.entity.sport; 导

我正在开发一个Springboot应用程序,它公开了一些端点,这些端点不返回原始实体,但返回了它们的DTO。为了映射我正在使用的所有实体,我使用“org.modelmapper”版本:0.7.4和ProjectLombok来避免实现getter、setter和其他一些实用程序

在我必须映射实体上的子类列表之前,一切都很顺利。源实体如下所示(我删除了一些属性和hibernate注释,因为它们在示例中不是必需的):

package com.pfi.repository.entity.sport;
导入com.pfi.repository.entity.address.address;
进口龙目。*;
导入java.util.List;
@吸气剂
@塞特
@EqualsAndHashCode
@AllArgsConstructor
@诺尔格构装师
公共级运动场{
私人长id;
私人运动场;
}
目标DTO是:

包dto.sport;
进口龙目。*;
导入java.util.List;
@吸气剂
@诺尔格构装师
@塞特
公共级SportPlaceDTO{
私人长id;
私人运动场;
}
AbstractSportFieldDTO和AbstractSportField都是抽象类,具有两个可能的子类:

包dto.sport;
导入dto.reserve.AbstractReserveDTO;
导入java.util.List;
公共抽象类AbstractSportFieldDTO{
保护长id;
保护区名单;
公共摘要sportfielddto(){
}
公共摘要SportFieldDTO(长id,列表保留){
this.id=id;
这个。储备=储备;
}
公共长getId(){
返回id;
}
公共抽象sportfielddto setId(长id){
this.id=id;
归还这个;
}
公开名单{
收益准备金;
}
公共摘要SportFielddTo setReserves(列出保留区){
这个。储备=储备;
归还这个;
}
}
第一个DTO子类是:

包dto.sport;
导入dto.reserve.AbstractReserveDTO;
导入java.util.List;
公共类ComboSportFieldDTO扩展了AbstractSportFieldDTO{
私人运动场;
公共组合SportFieldDTO(列出sportFields){
this.sportFields=sportFields;
}
公共组合SportFieldDTO(长id、列表保留、列表sportFields){
超级(id,储备);
this.sportFields=sportFields;
}
公共组合sportfielddto(){
超级();
}
公共列表getSportFields(){
返回运动场;
}
公共字段(列出运动字段){
this.sportFields=sportFields;
}
}
第二个DTO子类是:

包dto.sport;
导入dto.reserve.AbstractReserveDTO;
导入java.util.List;
公共类SportFieldDTO扩展了AbstractSportFieldDTO{
私有布尔可连接;
公共SportFieldDTO(长id、列表保留、布尔可连接){
超级(id,储备);
this.joineable=可连接;
}
公共体育场地{
超级();
}
公共布尔getJoineable(){
返回可连接;
}
public void setJoineable(布尔可连接){
this.joineable=可连接;
}
}
那么这些实体是:

package com.pfi.repository.entity.sport;
导入com.pfi.repository.entity.reserve.AbstractReserve;
导入java.util.List;
公共抽象类AbstractSportField{
保护长id;
保护区名单;
公共抽象字段(长id,列表保留){
this.id=id;
这个。储备=储备;
}
公共运动场(){
}
公共长getId(){
返回id;
}
公共抽象字段集合id(长id){
this.id=id;
归还这个;
}
公开名单{
收益准备金;
}
公共体育场地设置保留地(列出保留地){
这个。储备=储备;
归还这个;
}
}
第一个子类是:

package com.pfi.repository.entity.sport;
导入com.pfi.repository.entity.reserve.AbstractReserve;
导入java.util.List;
公共类ComboSportField扩展了AbstractSportField{
私人运动场;
公共ComboSportField(长id、列表保留、列表sportFields){
超级(id,储备);
this.sportFields=sportFields;
}
公共字段(){
超级();
}
公共列表getSportFields(){
返回运动场;
}
公共组合SportField setSportFields(列出sportFields){
this.sportFields=sportFields;
归还这个;
}
}
最后一个子类是:

package com.pfi.repository.entity.sport;
导入com.pfi.repository.entity.reserve.AbstractReserve;
导入javax.persistence.Entity;
导入java.util.List;
公共类SportField扩展了AbstractSportField{
私有布尔可连接;
公共运动场(长id、列表保留、布尔可连接){
超级(id,储备);
this.joineable=可连接;
}
公共运动场(){
超级();
}
公共布尔getJoineable(){
返回可连接;
}
公共SportField设置可连接(布尔可连接){
this.joineable=可连接;
归还这个;
}
}
当我尝试将SportPlace实例映射到SportPlaced时,如下所示:

modelMapper.map(sportPlace,SportPlaceDTO.class)
该de-sportPlace包含作为子类实例的给定6个Sportfields。模型映射器抛出(在列表的6个元素上):

未能实例化目标dto.sport.AbstractSportFieldDTO的实例。确保dto.sport.AbstractSportFieldDTO具有非私有的无参数构造函数

在阅读有关如何在modelmapper上映射子类的内容时,我发现设置TypeMap可以在如下类上设置特定映射:

modelMapper.createTypeMap(ComboSportField.class、ComboSportFieldDTO.class)

为了这个