文章目录
1.连接mongodb数据报的异常
首先检查是不是用户名和密码的错误参考
Caused by: com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=null, userName='root', source='admin', password=<hidden>, mechanismProperties={}}}, caused by {com.mongodb.MongoCommandException: Command failed with error 18: 'Authentication failed.' on server localhost:27017. The full response is { "ok" : 0.0, "errmsg" : "Authentication failed.", "code" : 18, "codeName" : "AuthenticationFailed" }}}]
2.在读取yml文件的时候报错。不能去取yml配置文件。
java.nio.charset.MalformedInputException: Input length = 1
at java.nio.charset.CoderResult.throwException(CoderResult.java:260)
at java.nio.charset.CharsetDecoder.decode(CharsetDecoder.java:781)
—
解决方法:把yml文件中的中文注解删除,看是否还报错 ,是不是编码的问题。如果是修改编码全部为UTF-8.包括右下角的也给修改了、
3.java.net.BindException: Address already in use: bind
4.使用注解将类加入到spring容器中,但是该类没有变色。
解决:查看自己的引导类有没有写,写了的话,看需不需要额外添加包的扫描。
5.方法请求的时候直接报错RFC 7230 and RFC 3986
java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
解决方法:
将Get请求变成Post请求,并且在请求参数的位置加上@RequestBody注解
参考文章,点击这里
参考文章2,点击这里
2.在springboot工程中增加一个tomcat 配置,或者将webServerFactory方法加入到springboot启动类中,配置文件代码如下:
/**
* @author: zw
* @create: 2019-06-27 11:19
**/
@Configuration
public class TomcatConfig {
@Bean
public TomcatServletWebServerFactory webServerFactory() {
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
factory.addConnectorCustomizers((Connector connector) -> {
connector.setProperty("relaxedPathChars", "\"<>[\\]^`{|}");
connector.setProperty("relaxedQueryChars", "\"<>[\\]^`{|}");
});
return factory;
}
}
在方法中我们加入了 \"<>[\\]^`{|}这些符号,问题就这么完美的解决了
6.在Mybatis进行查询的时候,报错数据库表出现错误
很有可能是驱动的问题,下面是正确的驱动
url: jdbc:mysql://192.168.31.116:3306/ruoyi?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
7.Mybatis映射失败
检查实体类的get/set方法是否书写了,添加@Data
8.java.lang.IllegalArgumentException: invalid comparison: java.util.Date and java.lang.String
原工程中配置的是mybatis-3.2.8, 而我测试工程中用的是mybatis-3.3.0.后来在网上找了一下才知道, 原来这是mybatis 3.3.0中对于时间参数进行比较时的一个bug. 如果拿传入的时间类型参数与空字符串’'进行对比判断则会引发异常. 所以在上面的代码中去该该判断, 只保留非空判断就正常了
<if test="createTime != null and createTime !='' " >
date(create_time) = date(#{createTime,jdbcType=TIMESTAMP})
</if>
改为
<if test="createTime != null">
date(create_time) = date(#{createTime,jdbcType=TIMESTAMP})
</if>