问题
这个问题的出现是,我单独新建实体(entity)和新建冲控制器(controller)是没问题的。
实体类如下:
@Data
@EqualsAndHashCode(callSuper = false)
@TableName(value = "test_data", keepGlobalPrefix = true)
@TableComment("测试数据")
@ApiModel(value = "测试数据")
public class TestData {
@ApiModelProperty(value = "数据标题")
@Column(comment = "数据标题", length = 50)
private String dataTitle;
@ApiModelProperty(value = "数据信息")
@Column(comment = "数据信息", length = 50)
private String dataInfo;
}
控制器如下:
@Api(tags = "用户端控制器")
@RestController
@RequestMapping("/DoTest")
public class TestDBController {
@ApiOperation(value = "获取数据")
@GetMapping("/test")
public List<TestData> test(@ApiParam(name = "id",value = "Id") Long id, @ApiParam(name = "name",value = "名称") String name){
List<TestData> list = new ArrayList<>();
return list;
}
}
能正常启动运行,但是当我创建了对应的mapper service serviceimpl controller 后就无法启动,而且不管是否有对应的处理逻辑。都无法启动工程,报错如下:
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name ‘**Controller’: Injection of resource
dependencies failed; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name '*ServiceImpl’: Unsatisfied dependency
expressed through field ‘baseMapper’; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'Mapper’ defined in file
[\TestDataMapper.class]: Invocation of init method failed; nested
exception is java.lang.NoSuchMethodError:
com.baomidou.mybatisplus.core.injector.AbstractMethod: method ‘void
init()’ not found
我顺着.NoSuchMethodError: com.baomidou.mybatisplus.core.injector.AbstractMethod: method ‘void ()’ 这个错误排查了很久始终没找到答案。
比如说mapper接口类中的@Mapper和启动类中的@MapperScan注解重复:
我这里也并未重复。
Application.yml文件中的mybatis-plus也正常配置:
Controller中的@RestController注解已加上:
ServiceImpl中的@Service注解已加上:
解决方法
所以以上的方式都不正确,我的问题是所有的代码都是能顺利通过编译,而启动项目的时候创建bean失败的问题。
因为是沿用了其它项目的pom.xml依赖,想着是完全不会有问题的,不过还是尝试将相近的依赖进行注释,知道我删除了mybatis-plus-join的依赖就能正常启动。
注释了一下内容:
<dependency>
<groupId>com.github.yulichang</groupId>
<artifactId>mybatis-plus-join</artifactId>
<version></version>
</dependency>
之后就能完全正常是用了,按理这个是MybatisPlus联合查询的插件,不至于会冲突,具体原因不详了,后续继续研究。
所以我这里的问题根源是 项目中的pom.xml依赖冲突。