BUG01
字符串比较相等要用equals()方法,不能用==!!!!!
BUG02
现象:使用Postman发送请求时报错:unsupported media type 415
原因:传参的格式没有指定
解决:在请求头加上Content-Type:application/json
BUG03
现象:使用命令mvn clean package -Dmaven.test.skip打war包时报错:DependencyResolutionException,但是项目在IDEA上是可以运行的
原因:Maven的本地仓库配置不知道什么时候被注释掉了
解决:在setting.xml文件中重新配置本地仓库
BUG04
现象:使用命令mvn clean package -Dmaven.test.skip打war包时报错:Fatal error compiling: 无效的目标发行版: 11
原因:因为项目的要求不同,我使用了多个版本的JDK,在环境变量中配置的JDK版本是1.8
解决:去环境变量中把JAVA_HOME的路径改成JDK11的
BUG05
现象:访问接口时报错:Could not resolve view with name 'xxx' in servlet with name 'dispatcherServlet'"
{
"timestamp": 1627462611130,
"status": 500,
"error": "Internal Server Error",
"exception": "javax.servlet.ServletException",
"message": "Could not resolve view with name 'admin/zixunspider/saveSpider' in servlet with name 'dispatcherServlet'",
"path": "/admin/zixunspider/saveSpider"
}
原因:当Controller层的返回对象为json时,不能@Controller注解
解决:
- 将@Controller注解改为@RestController(该项目中该方法所在类的其它方法有的返回到指定页面,所以不能用@RestController直接替换@Controller)
- 在需要请求的返回json对象的方法上添加@ResponseBody注解
BUG06
现象:使用es进行聚合搜索时报错:
org.elasticsearch.ElasticsearchException: Elasticsearch exception
[type=illegal_argument_exception, reason=Text fields are not optimised for operations that
require per-document field data like aggregations and sorting, so these operations are disabled
by default. Please use a keyword field instead. Alternatively, set fielddata=true on [hsmid] in
order to load field data by uninverting the inverted index. Note that this can use significant
memory.]
原因:产生该错误的原因是因为该字段(类型为Text的字段)不支持聚合或者排序。
解决:text类型的字段自带一个类型为keyword的子字段,可以使用此字段进行排序和聚合。
将代码:
AggregationBuilder termsAggregationBuilder = AggregationBuilders.terms("housec").field("hsmid").size(500)
.shardSize(50000).minDocCount(2).shardMinDocCount(1);
改为
AggregationBuilder termsAggregationBuilder = AggregationBuilders.terms("housec").field("hsmid.keyword").size(500)
.shardSize(50000).minDocCount(2).shardMinDocCount(1);
BUG07
又遇到了和上面一样的错误(报错信息是一样的),不过这次是因为Text类型不能用来进行排序(上面是不能进行聚合)
现象:使用es进行聚合搜索时报错:
org.elasticsearch.ElasticsearchException: Elasticsearch exception
[type=illegal_argument_exception, reason=Text fields are not optimised for operations that
require per-document field data like aggregations and sorting, so these operations are disabled
by default. Please use a keyword field instead. Alternatively, set fielddata=true on [hsmid] in
order to load field data by uninverting the inverted index. Note that this can use significant
memory.]
引起错误的代码:
FieldSortBuilder sanmaSortBuilder = SortBuilders.fieldSort("houseCode").order(SortOrder.DESC);
原因:houseCode字段的类型是Text,所以不支持排序

解决:
首先,按照上面的改法也没用
之前就按照他的报错信息改过,把houseCode字段的类型改成Keyword或者加上fielddata=true,但都不起作用
这次改完字段的类型后打开kibana查看索引的mapping发型类型没改,然后用命令行改houseCoder的类型,发现报错:Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true意思就是类型不支持修改
最终想到一个办法就是把索引删了,把houseCode字段类型修改为Keyword后,重新插入数据,解决问题

这篇博客列举了7个在Java开发中遇到的常见问题,包括字符串比较、POST请求参数格式、Maven本地仓库配置、多版本JDK环境变量、Controller与RESTful注解使用、Elasticsearch聚合搜索及Text字段排序错误,并提供了相应的解决方法。
470

被折叠的 条评论
为什么被折叠?



