我正在尝试启动一个springboot应用程序。但当它启动时,我收到一条错误信息:
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 1 of constructor in spring_boot.controller.RekeningController required a bean of type 'spring_boot.mappers.RekeningMapper' that could not be found.
Action:
Consider defining a bean of type 'spring_boot.mappers.RekeningMapper' in your configuration.
我试图在rekeningmapper中添加@bean注解,但效果不太好。我在网上到处搜索,但找不到解决办法。
下面我放置了它影响的代码。
雷克宁制图器
package spring_boot.mappers;
//Imports
@Mapper(componentModel = "spring")
public interface RekeningMapper {
RekeningDto naarRekeningDto(Rekening rekening);
Rekening naarRekeningModel(RekeningDto rekeningDto);
@Mapping(source = "rekeningen", target = "rekeningenIDs")
RekeningHouderDto naarRekeningHouderDto(RekeningHouder rekeningHouder);
RekeningHouder naarRekeningHouderModel(RekeningHouderDto rekeningHouderDto);
default List<String> rekeningToRekeningIds(List<Rekening> rekeningen) {
List<String> ids = new ArrayList<>();
for (Rekening rek : rekeningen)
ids.add(rek.getRekening_id());
return ids;
}
}
雷克宁控制器
package spring_boot.controller;
// Imports
@RestController
@RequestMapping("rekeningen")
public class RekeningController {
private RekeningService rekeningService;
private final RekeningMapper rekeningMapper;
@Autowired
public RekeningController(RekeningService rekeningService, RekeningMapper rekeningMapper) {
this.rekeningMapper = rekeningMapper;
this.rekeningService = rekeningService;
}
@GetMapping
public ResponseEntity<List<RekeningDto>> getAllRekeningen() {
List<Rekening> rekeningen = this.rekeningService.getAllRekeningen();
List<RekeningDto> rekeningDtos = new ArrayList<>();
for (Rekening rekening : rekeningen)
rekeningDtos.add(rekeningMapper.naarRekeningDto(rekening));
return ResponseEntity.ok(rekeningDtos);
}
}
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.0.Final</version>
</dependency>
1条答案
按热度按时间xsuvu9jc1#
您的依赖项和mapstruct处理器插件需要如下所示。将源和目标更新到您正在使用的java版本。还要确保您的项目使用的是Java1.8或更高版本(项目属性)→ "“java编译器”→ "编译符合性级别“)。它不适用于旧版本。
此外,要再次检查是否一切正常,请转到项目的属性并选择“java编译器”→ "“注解处理”→ "工厂路径”。mapstruct处理器jar应该在这里列出并启用