1. MySQL5.7版本sql_mode=only_full_group_by问题解决办法
原因:MySQL中的sql_mode属性中有only_full_group_by属性
only_full_group_by属性:Mysql的5.7.x版本中默认是开启sql_mode = only_full_group_by。而在这个模式下,我们使用分组查询时,出现在select字段后面的只能是group by后面的分组字段,或使用聚合函数包裹着的字段。
bug
Error querying database. Cause: java.sql.SQLException: Data truncated for column ‘getChildIdList(0)’ at row 1Error querying database.
解决方法:
- 查看sql_mode
SELECT @@sql_mode;
- 查询出来的值为:
ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
- 去掉ONLY_FULL_GROUP_BY,重新设置值。
SET @@global.sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
- 上面是改变了全局sql_mode,对于新建的数据库有效。对于已存在的数据库,则需要在对应的数据下执行:
SET sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
2.接口JSON类型不匹配
JSON parse error: Cannot deserialize instance of `java.util.ArrayList` out of VALUE_STRING token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.ArrayList` out of VALUE_STRING token
at [Source: (PushbackInputStream); line: 1, column: 77] (through reference chain: com.gxxw.video.vo.device.DeviceSaveRequestParam["groupId"])
解决问题:
将JSON类型修改成一致
3. SoringBoot 测试FrameworkApplicationTests无法启用
bug
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serverEndpointExporter' defined in class path resource [com/gxxw/video/modules/from/home/socket/WebSocketConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: javax.websocket.server.ServerContainer not available
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1778)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:845)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:742)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:389)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:311)
at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:119)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117)
... 24 common frames omitted
Caused by: java.lang.IllegalStateException: javax.websocket.server.ServerContainer not available
at org.springframework.util.Assert.state(Assert.java:73)
at org.springframework.web.socket.server.standard.ServerEndpointExporter.afterPropertiesSet(ServerEndpointExporter.java:106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1837)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1774)
... 39 common frames omitted
问题解决:
在@SpringBootTest
加入属性webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
原因:
- WebSocket是servlet容器所支持的,所以需要加载servlet容器。
- webEnvironment参数为springboot指定ApplicationContext类型。
- webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT表示内嵌的服务器将会在一个随机的端口启动。
4. 依赖包版本低问题
bug
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication....
修改版本到最新
5 有时候idea不启动,一样可以运行网站
bug:无法刷新,不启动idea一样可以访问
原因:可能是因为项目没有完全关闭Java(TM)Platform SE binary
解决方法:打开任务管理器找到多余的Java(TM)Platform SE binary,结束,就可以解决问题
6.修改dao接口路径后常见问题
原因:没有修改xxxMapper.xml中的路径,导致dao接口找不到该方法,无效的绑定语句(未找到):
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.example.video_analy.modules.schedule.dao.ScheduleJobDao.updateBatch
at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:235)
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.<init>(MybatisMapperMethod.java:49)
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.lambda$cachedMapperMethod$0(MybatisMapperProxy.java:65)
at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.cachedMapperMethod(MybatisMapperProxy.java:65)
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:60)
at com.sun.proxy.$Proxy111.updateBatch(Unknown Source)
at com.example.video_analy.modules.schedule.service.impl.ScheduleJobServiceImpl.updateBatch(ScheduleJobServiceImpl.java:108)
at com.example.video_analy.modules.schedule.service.impl.ScheduleJobServiceImpl.resume(ScheduleJobServiceImpl.java:138)
at com.example.video_analy.modules.schedule.service.impl.ScheduleJobServiceImpl$$FastClassBySpringCGLIB$$cde9f196.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
解决方法:将对于的接口Mapper.xml文件修改路径
7.spring循环依赖的问题:has been injected into other beans
bug
Bean with name 'configAreaServiceImpl' has been injected into other beans [configDeviceServiceImpl] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.
原因:首先说一下什么是依赖循环,比如:我现在有一个ServiceA需要调用ServiceB的方法,那么ServiceA就依赖于ServiceB,那在ServiceB中再调用ServiceA的方法,就形成了循环依赖。Spring在初始化bean的时候就不知道先初始化哪个bean就会报错。
解决:互相依赖的两个bean上加上@Lazy注解也可以
7. Linux大小写区分,导致部署项目时MySQL出现错误
报错:java.sql.SQLSyntaxErrorException: Table ‘examsys.Teacher’ doesn’t exist
问题原因:找不到Teacher这张表。因为在windows下的mysql表名不区分大小写,所以在windows下运行项目没问题。在linux中,mysql会区分大小写,所以sql语句表名用大写的就会找不到表
解决问题:
方法一(mysql8以下的版本):
- 修改mysql配置文件:/etc/my.cnf 。在文件头部[mysqld]下方添加如下语句。
#设置mysql表不区分大小写
lower_case_table_names=1
之后重启mysql服务即可。
systemctl restart mysqld
方法二(最土的办法):
代码量不多的话,就把所有的sql语句的表名全部换成小写的重新打包上传。
8. 跨域问题
bug: 出现问题前端项目点击无反应,后端项目无问题
解决方法:
查看前端请求
检查iP地址,如果不对可以修改过来,如果是本地部署的就不需要改了,如果是服务器部署的需要将前端的index.js中的IP接口改成服务器公网的,检查前后端的端口号要一致。
9、 端口占用Identify and stop the process that‘s listening on port 8080 or configure thi
查看端口命令
netstat -aon|findstr "8080"
杀掉端口
taskkill /pid 13620 /f
10 idea打开前端出现缓存问题导致出现错误打不开
清理缓存命令:
npm cache clean --force
重新安装一次即可
npm install
11 前端打包错误 npm ERR! missing script: build,npm run build无法打包的可能原因
结果报错npm ERR! missing script: build,后来发现package.json中scripts参数为
“scripts”: {
“dev”: “vue-cli-service serve”,
"build:prod": “vue-cli-service build”,
“build:stage”: “vue-cli-service build --mode staging”,
“preview”: “node build/index.js --preview”,
“lint”: “eslint --ext .js,.vue src”,
“test:unit”: “jest --clearCache && vue-cli-service test:unit”,
“test:ci”: “npm run lint && npm run test:unit”,
“svgo”: “svgo -f src/icons/svg --config=src/icons/svgo.yml”
},
所以正确的命令应该为
npm run build:prod --report
13 前端打包错误:npm ERR! A complete log of this run can be found in
错误数据:
说明:全局脚手架和本地脚手架版本不一样。
解决方法:
执行 npm install npm@latest -g升级到最新版本(若升级到最新版本还是报错,则还需要再全局更新一下npm,更新后检查npm版本号不会变,内部应该有更新);
.删除本地node_modules 依赖包;
执行 npm cache clean --force 清理缓存;
npm i 安装依赖;
以上过程,尝试一次不行,可以多尝试几次就OK了
14 部署SpringBoot项目修改Maven配置后,pom爆红,无法下载包
描述:不修改idea中的maven不报错,但是修改成自己的maven,pom文件会爆红
解决方法:
清除缓存就可以了,然后重新下载包,这个问题就可以解决了
15 当使用mybatis plus 更新方法想将某一个字段中的值修改为空时,修改失败
原因:mybatis plus 中的修改方法默认字段为空时不修改数据库中的值
解决方法:在需要当值为null时一样修改的实体类字段加上注解
@TableField( updateStrategy = FieldStrategy.IGNORED)
加上后,该字段为空时,就一样会进行修改
注意:加入该注解之后,只要是更新使用到该实体,都会根据更新时该字段的值来修改该字段,不会忽略为空。
16 Node Sass could not find a binding for your current environment: Windows 64-bit with Node.js 7.x
错误原因:项目node版本和系统版本不一致
解决方法:
在项目路径使用命令
npm rebuild node-sass
npm update
17 在使用Navicat往数据库里导入数据时,出现了错误:[Err] 1153 - Got a packet bigger than ‘max_allowed_packet’ bytes
了解后发现,当MySQL客户端或mysqld服务器收到大于max_allowed_packet字节的信息包时,将发出“信息包过大”错误,并关闭连接,MySQL默认读取执行的SQL文件最大为16M。
对于某些客户端,如果通信信息包过大,在执行查询期间,可能会遇到“丢失与MySQL服务器的连接”错误。
解决方法:
找到my.cnf,修改max_allowed_packet选项
find /etc -name my.cnf
vim /etc/my.cnf
添加变量
max_allowed_packet=100M
保存重启mysql服务器
systemctl restart mysqld.service
或者
service mysqld restart