本文集合了一些新人在javaweb入门阶段可能遇到的问题,持续更新。
问题一
问题描述
idea控制台中文日志乱码
解决方法1
在菜单栏找到HELP->Edit Custom VM OPtions中加 -Dfile.encoding=utf-8
-Xms128m
-Xmx2032m
-XX:ReservedCodeCacheSize=240m
-XX:+UseConcMarkSweepGC
-XX:SoftRefLRUPolicyMSPerMB=50
-ea
-XX:CICompilerCount=2
-Dsun.io.useCanonPrefixCache=false
-Djdk.http.auth.tunneling.disabledSchemes=""
-XX:+HeapDumpOnOutOfMemoryError
-XX:-OmitStackTraceInFastThrow
-Djdk.attach.allowAttachSelf=true
-Dkotlinx.coroutines.debug=off
-Djdk.module.illegalAccess.silent=true
##这句
-Dfile.encoding=utf-8
解决方法二
设置idea server编码。在菜单栏找到”run->editconfigration” 找到”server”选项卡 设置 vm option为 -Dfile.encoding=utf-8,如图3所示
问题二
问题描述
IDEA 2020 bug IDEA 编译出现的问题 Error:(5, 47) java: 程序包org.springframework.web.bind.annotation不存在
解决方法:File>Settings>Build, Execution, Deployment>Build Tools>Maven>Runner>Delegate IDE… 这个选项勾选
问题三:
问题描述
batis.binding.BindingException: Invalid bound statement (not found)
解决思路
检查自己的mapper文件与dao文件名是否一样;
- DAO 接口名一定要与 Mapper 文件的名称一模一样;
- Mapper 文件中的 namespace 路径一定要与 DAO 接口的路径一致;
- Mapper 文件必须要放置到 resources 目录中,否则不会被编译;
- resources 目录中的 Mapper 文件的路径一定要与 DAO 接口的路径完全一致。
问题四
问题描述:
Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user 'root'@'localhost' (using password: YES))
java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
解决思路
有可能是你的mysql密码错误。
问题五
问题描述
java.sql.SQLException: Unknown system variable 'query_cache_size'
解决思路
在5.7中可以使用的一些类和数据库驱动,在mysql8.0中就不能使用,或者被丢弃了。更换自己的pom.xml里mysql-connector-java
版本。
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.11</version>
</dependency>
同时还要将jdbc.driver=com.mysql.jdbc.Driver
改为jdbc.driver=com.mysql.cj.jdbc.Driver
问题七
问题描述
#1
Cannot create PoolableConnectionFactory (The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.)
#2
Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the connection string near
解决思路
在数据源配置后面增加一个&serverTimezone=UTC
,如下所示
##增加前
jdbc.url=jdbc:mysql://localhost:3306/movie?useUnicode=true&characterEncoding=utf8&useSSL=false
##增加后
jdbc.url=jdbc:mysql://localhost:3306/movie?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC