学习spring的路上遇到的一些坑,以此来记录,以免之后重蹈覆辙。
1.Inferred type ‘S’ for type parameter ‘S’ is not within its bound; should extend 'com.example.myspringboot.model.SysApp’
spring-boot整合JPA时遇到的错误
解决方案:
首先感谢Roy-Xin博主,方法很有效的解决了问题
1.可能是spring把本的问题,将高版本换成1.5.4的版本。(这个当时也懒得换,烦导包)
2.直接将图中的sysAppDao.findOne(id)
改为 sysAppDao.findById(id).get()
,或者改为sysAppDao.findById(id).orElse(null)
2.Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: 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
或者
springboot com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
spring连接数据库时出现的错误,有时候出现的错误时Failed to linked!
解决方案:
刚开始查这个错误的时候以为是数据库版本的问题,还有要设置本地数据库的连接超时项,但是都没什么改变,还是报错。
最后发现我的url为jdbc:mysql://127.0.0.1:3306/java-test?characterEncoding=utf-8&useSSL=false
,jdbc.driverClassName = com.mysql.cj.jdbc.Driver
在这两个地方出了错。
改为jdbc:mysql://127.0.0.1:3306/java-test?serverTimezone=GMT%2B8&useUnicode=yes&characterEncoding=utf-8&useSSL=false
就可以了。
3.The bean ‘xxx’, defined in null, could not be registered. A bean with that name has already been defined in file [E:\java work\myspringboot\target\classes\com\example\myspringboot\mapper\SysMapper.class] and overriding is disabled.
这个错误是在整合jpa的时候遇到的,当时直接和target包中的类重名了,我很郁闷呐,但还是按照系统的解决办法解决了。
解决方案:
在配置文件中(我的是application.properties文件)中添加配置spring.main.allow-bean-definition-overriding=true
启用覆盖就可以了。有时候也可能是bean的名称重名了,更改其中一个bean的名字也是可以的。