问题描述:代码编译不通过,出Error creating bean with name '***Controller’异常
**解决BUG** **Error creating bean with name '***Controller'** **Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1**Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-09-27 21:39:49.780 ERROR 7212 --- [ main] o.s.boot.SpringApplication : Application run failed
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name .....
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
原因分析:
问题的分析:
Error creating bean with name
1.clean-install
2.检查@service, @Controller注解
3.检查是否扫描包
4.查看包名是否写错
5.尝试重启idea(这货有时会发呆)
经过上述分析,没能查出我的错误,最会一个点没分析那就是实体类了,于是检查实体类.
/**
* @program: changgou_parent
* @description:shop_*
* @author: Mr.Z
* @create: 2020-09-27 15:35
**/
@Table(name="tb_category_brand")
public class CategoryBrand implements Serializable {
@Id
private int shop_categoryId;
@Id
private int shop_brandId;
看到这里 突然想起来自己用到了通用mapper 而通用mapper源码如下
public interface Mapper<T> extends
BaseMapper<T>,
ExampleMapper<T>,
RowBoundsMapper<T>,
Marker {
}
事情变得清晰起来了!
于是将int类型改为包装类Integer 重启idea ,编译通过,问题解决!!
解决方案:
将entry实体类int类型 改为Integer
拓展知识:
包装类和基本类型区别
1.包装类可以自动拆箱装箱
2.包装类可以为null值
3.包装类可以用于泛型
4.包装类是基本类型的包装 所以基本类型的性能会更优
5.包装类相对于基本类型更加符合java 面向对象的思想.