天天看点

SpringBoot中报错Inferred type ‘S‘ for type parameter ‘S‘ is not within its bound的解决办法问题描述:原因分析:解决方案:

问题描述:

今天在写项目时候,service层中的一个方法报错如下:

Inferred type 'S' for type parameter 'S' is not within its bound;
should extends xxxxxx
           

解决了很久,刚开始以为自己写错了,但是检查后没有问题,最后发现原来是SpringbBoot的版本问题。

原因分析:

SpringBoot 版本问题,SpringBoot 2.0后新特性。

解决方案:

1、修改版本,降为SpringBoot 1.5.x;(已尝试并解决)

截图如下:

SpringBoot中报错Inferred type ‘S‘ for type parameter ‘S‘ is not within its bound的解决办法问题描述:原因分析:解决方案:

代码如下:

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

2、 修改代码:

修改前:  return this.userRepository.findOne(id);
	修改后:  return this.userRepository.findById(id).orElse(null);