项目踩坑记录1

文章目录

    • :bug:目录
            • :ant:1:主要报错:SQLGrammarException,MySQLSyntaxErrorException,InvalidDataAccessResourceUsageException
            • 2:Nginx无法启动
            • 3:报错信息:java.lang.RuntimeException: com.netflix.client.ClientException,feign.FeignException
            • 4:杂项idea-maven-字符串拼接
            • 5:java写json串时可以先定义map,再将map转成json
            • 6:报错:RestClientException,BeanCreationNotAllowedException,IllegalStateException

目录

1:主要报错:SQLGrammarException,MySQLSyntaxErrorException,InvalidDataAccessResourceUsageException
详细报错:
1:org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
2:Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
3:Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'teachplanm0_.course_id' in 'field list'
错误原因:数据库字段名courseid与javabean实体类字段名称courseId大小写不一致;
解决:在javabean实体类字段名courseId上加上注解@Column(name = "courseid")并指定数据库字段名称courseid
注意:如果此注解@Table(name = "teachplan_media_pub")中的name的值(javabean实体类对应的表名称)写错的话也会报和上面相同的错误;
2:Nginx无法启动
现象:windows版nginx直接双击nginx.exe文件无法启动服务,不知道是什么原因;
解决过程:通过cmd命令行启动,有错误信息。是配置文件配置错误,导致无法启动。
解决:修改配置文件
启发:启动nginx时或其他软件时,当无法启动时,可以使用cmd命令行启动,可以看到报错信息
3:报错信息:java.lang.RuntimeException: com.netflix.client.ClientException,feign.FeignException
详细报错
1:exception:
java.lang.RuntimeException: com.netflix.client.ClientException: Load balancer does not have available server for client: xc-service-search
2:exception:
feign.FeignException: status 404 reading CourseSearchClient#getmedia(String); content:
{"timestamp":"2020-03-08T09:04:50.635+0000","status":404,"error":"Not Found","message":"No message available","path":"/getmedia/4"}
问题原因:
package com.xuecheng.learning.client;

import com.netflix.loadbalancer.ServerList;
import com.xuecheng.framework.client.XcServiceList;
import com.xuecheng.framework.domain.course.TeachplanMediaPub;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@FeignClient(value = XcServiceList.XC_SERVICE_SEARCH)
public interface CourseSearchClient {
    //根据课程计划id查询课程媒资
    @GetMapping(value="/search/course/getmedia/{teachplanId}")
    public TeachplanMediaPub getmedia(@PathVariable("teachplanId") String teachplanId);
}
上面代码@GetMapping(value="/search/course/getmedia/{teachplanId}")中的地址写错;
解决:通过swagger查找正确的访问地址,并修改;
4:杂项idea-maven-字符串拼接
1:使用idea中遇到的依赖报错问题,当依赖的版本报红时,可以右键代码空白处,然后然后选择maven——》reimport 刷新即可
2:在导入maven依赖时,直接复制粘贴全部依赖时会报错。只有一个一个手动导入才正常。(注意不能复制粘贴,只能手动导入)
3:在idea中使用maven工程导入pom依赖时,pom文件中的依赖有报错,但是在maven本地仓库中是有所依赖的jar包的,此时应该进入maven的设置中,更新maven仓库的依赖
具体步骤如下 setting   ->   搜索maven  ->  Repositores  ->  update  
4:在拼接字符串是要尽量使用Stringbuffer或者Stringbuilder尽可能不适用+号拼接,这样当需要拼接的字符串比较多时,可以很明显的提高程序的效率。
5:java写json串时可以先定义map,再将map转成json
使用com.alibaba.fastjson
//定义payload信息
        Map<String, Object> tokenMap = new HashMap<>();
        tokenMap.put("id", "123");
        tokenMap.put("name", "mrt");
        tokenMap.put("roles", "r01,r02");
        tokenMap.put("ext", "1");
        //将map转成json串
        String jsonString = JSON.toJSONString(tokenMap);
		//json串转换成map
        Map jsonObject = JSON.parseObject(jsonString);
6:报错:RestClientException,BeanCreationNotAllowedException,IllegalStateException
1:org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class org.hibernate.mapping.Map] and content type [application/json;charset=UTF-8]

2:org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'eurekaAutoServiceRegistration': Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)

3:java.lang.IllegalStateException: Shutdown in progress

报错原因分析:由第一段报错信息可以看出错误与响应的类型有关,然后通过控制台具体定位到报错代码所在行,发现是导包导错了。应该导入import java.util.Map包,却导成了import org.hibernate.mapping.Map包

到报错代码所在行,发现是导包导错了。应该导入import java.util.Map包,却导成了import org.hibernate.mapping.Map包


你可能感兴趣的:(bug,springboot)