关于springboot注解使用

场景复现:

String sql = "SELECT s.begin_time,s.end_time FROM SCHEDULE s WHERE s.class_id = ? AND s.lesson_id = ?";

ScheduleAddVo scheduleAddVo = myJdbcTemplate.queryForObject(sql,new Object[]{classId,lessonId},new BeanPropertyRowMapper<>(ScheduleAddVo.class));

原因探究:
使用springboot实现一定要注意的点::
必须在实体类具有无参构造方法
使用springboot进行测试时候一直报错

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.aixuexi.xiuchun.test.PageListMongodbTest': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.gaosi.api.xiuchun.service.RequestTraceService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup=, name=, description=, authenticationType=CONTAINER, type=class java.lang.Object, mappedName=)}

解决办法:
解决办法在service实现加上注解
@com.alibaba.dubbo.config.annotation.Service

还有可能就是dao层的类上没有加上注解 @Reposity

switch case break 基本语法规则

我们在dao层写查询数据库时候老师容易报各种异常:

org.springframework.jdbc.IncorrectResultSetColumnCountException: Incorrect column count: expected 1, actual 5
这时候检查发现报错
return myJdbcTemplate.query(sql,new Object[]{type,classType,lessonId},new BeanPropertyRowMapper<>(SearchQuestionDto.class));  

BeanPropertyRowMapper默认将我们返回的值转成list<对象名>
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException

三种可能的异常,第一种是dao层没有加注解,第二是service的注解导包错误,三是dubbo的service没有注册
依赖版本报错,所以一般是pom.xml文件的错误

猜你喜欢

转载自blog.csdn.net/baidu_34168157/article/details/80321335