电商项目|品优购商城项目常见BUG解析

1.(Initializing ProtocolHandler) 端口被占用异常。tomcat重复启动所致。*
信息: Initializing ProtocolHandler [“http-bio-9001”]
三月 20, 2019 9:01:47 上午 org.apache.coyote.AbstractProtocol init
严重: Failed to initialize end point associated with ProtocolHandler [“http-bio-9001”]
java.net.BindException: Address already in use: JVM_Bind :9001
**2.在注册中心找不到对应的服务

java.lang.IllegalStateException: Failed to check the status of the service** com.pinyougou.sellergoods.service.BrandService. No provider available for the servicecom.pinyougou.sellergoods.service.BrandService from the url zookeeper://192.168.25.129:2181/com.alibaba.dubbo.registry.RegistryService?application=pinyo ugou-manager web&dubbo=2.8.4&interface=com.pinyougou.sellergoods.service.BrandService&methods=updat e,get,delete,selectOptionList,add,getListByPage&pid=3980&revision=0.0.1 SNAPSHOT&side=consumer×tamp=1501146823396 to the consumer 172.16.17.14 use dubbo version 2.8.4

【电商项目|品优购商城项目常见BUG解析】这种错误是服务层代码没有成功注册到注册中心导致,请检查一下你的服务层代码是否添加 了@service 注解,并且该注解的包一定是 com.alibaba.dubbo.config.annotation 包,不是 org.springframework.stereotype.Service,这个地方极容易出错。另外还有一个原因就是你的 服务层工程由于某些原因没有正常启动,也无法注册到注册中心里。
3.无法连接到注册中心
timeout: 5000 org.I0Itec.zkclient.exception.ZkTimeoutException: Unable to connect to zookeeper server within timeout: 5000 org.I0Itec.zkclient.ZkClient.connect(ZkClient.java:876) org.I0Itec.zkclient.ZkClient.(ZkClient.java:98) org.I0Itec.zkclient.ZkClient.(ZkClient.java:92) org.I0Itec.zkclient.ZkClient.(ZkClient.java:80) com.alibaba.dubbo.remoting.zookeeper.zkclient.ZkclientZookeeperClient.(ZkclientZook eeperClient.java:26)

请检查 IP 与端口是否填写正确,检查注册中心是否正常启动
4.子项目中pom文件图标不正确,无法正常创建webapp目录 。
../pinyougou_pojo ../pinyougou_dao ../pinyougou_common ../pinyougou_sellergoods_interface ../pinyougou_sellergoods_service ../pinyougou_manager_web ../pinyougou_shop_web

请检查父工程中是否有导入子工程。而后在maven中选中项目,点击刷新即可。
5.在做增加和修改方法时,主键id增加但是没有输入的值。
/** * 添加方法 * @param tbBrand */ @RequestMapping("/add.do") public SuccessMessage testAdd(@RequestBody TbBrand tbBrand){ //判断名称是否重复 开始 -↓- String name = tbBrand.getName(); List all = brandService.findAll(); for (TbBrand brand : all) { String brandName = brand.getName(); if(name.equals(brandName)){ return new SuccessMessage(false,"重复名称!"); } } //判断名称是否重复 结束 -↑-//添加方法开始 -↓- try { brandService.add(tbBrand); return new SuccessMessage(true,""); } catch (Exception e) { e.printStackTrace(); return new SuccessMessage(false,"保存失败"); } //添加方法结束 -↑-}

请检查传入的参数中是否有@RequestBody注解。
6.在做删除方法时,遇到java NullPointerException(空指针异常)
请检查前端参数与后台参数的名称是否一致。
7.在前端js代码分层时,遇到无法读取未定义的“success”
//前台报错信息 angular.min.js:80 TypeError: Cannot read property 'success' of undefined at a.$scope.search (brandController.js:75) at a.$scope.reloadList (baseController.js:6) at Object.onChange (baseController.js:15)

未在方法前加return 返回。则会报无法定义success。
//搜索 this.search=function (page,size,searchEntity) { return$http.post("../brand/search.do?page=" + page + "&size=" + size, searchEntity); };

调用JS的service层 没有return返回值
8.、在前端js代码分成时,遇到前台报$scope未定义
//代码示例 app.service("brandService",function ($http) {//读取列表数据绑定到表单中 this.findAll=function () { //.get获取后端控制器层的方法 return $http.get("../brand/findAll.do"); };

在服务处js页面,方法的调取应该使用 this. 而非$scope.
9.在做新增规格选项时,定义方法后,按钮无法使用。控制台报错。
angular.min.js:80 TypeError:
Cannot read property 'specificationOptionList' of undefined at h.$scope.addTableRow (specificationController.js:82) at angular.min.js:158 at angular.min.js:175 at h.$eval (angular.min.js:98) at h.$apply (angular.min.js:99) at HTMLButtonElement. (angular.min.js:175) at HTMLButtonElement.dispatch (jquery-2.2.3.min.js:3) at HTMLButtonElement.r.handle (jquery-2.2.3.min.js:3)

查看specificationController.js第82行,
$scope.entity.specificationOptionList.push({}); 为null值,需要定义后方可使用。
//修改后代码 $scope.entity={specificationOptionList:[]}; $scope.addTableRow=function(){ $scope.entity.specificationOptionList.push({}); }

10、在登陆后台时,报错 “创建名为…的bean时出错”。
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.DefaultSecurityFilterChain#6':

重启虚拟机,重启idea即可。
11、在做solr添加索引时遇到Document is missing mandatory uniqueKey field: id(文档缺少必需的uniquekey字段:id)
public void importItemData(){ TbItemExample example=new TbItemExample(); TbItemExample.Criteria criteria = example.createCriteria(); criteria.andStatusEqualTo("1"); //审核通过 List itemList = itemMapper.selectByExample(example); System.out.println("---商品列表---"); for (TbItem tbItem : itemList) { System.out.println(tbItem.getId()+"---"+tbItem.getTitle()+"---"+tbItem.getPrice()); }solrTemplate.saveBeans(itemList); solrTemplate.commit(); }

问题就出在solrTemplate.saveBean(selectByExample); 这段代码上导致了Document is missing mandatory uniqueKey field: id这个错误信息,正确的是solrTemplate.saveBeans(selectByExample); 这个错误很尴尬,由于两个方法很相似,调用的时候要看仔细。

    推荐阅读