1.生成springboot项目后,修改了包的默认路径或包名,项目跑不起了,怎么办!比如把com.example.demo改为com.demo
报错:找不到或无法加载主类com.example.demo.DemoApplication
解决:找到pom.xml文件,找到:
修改为
这段代码相当于是定位主类的位置,<groupId>中写java包下一层的com开始一直到主类DemoApplication的上两层目录,<artifactId>中写主类DemoApplication的上一层目录
注意:!主类DemoApplication必须与dao、service包的上一级包同级,即
2.项目启动报错:
Field xxxDao in com.cms.service.impl.LoginServiceImpl required a bean of type 'com.cms.dao.xxxDao' that could not be found.
原因:没有扫描到xxxDao,bean生成失败
解决:在主类中增加方法@MapperScan(xxxDao所在的路径)
注意:!!注解MapperScan和ComponentScanne的区别:@ComponentScan是组件扫描注解,用来扫描@Controller @Service @Repository这类,主要就是定义扫描的路径从中找出标志了需要装配的类到Spring容器中;@MapperScan 是扫描mapper类的注解,就不用在每个mapper类上加@MapperScan了。两者可以同时使用
3.项目启动报错:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.cms.dao.LoginDao.getUserByAccount] with root cause
解决:参考网络上解决方案
注意:!!接口名与Mybatis的映射文件名一定要一模一样
4.从后台获取数据报错
错误:java.sql.SQLException: 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.
原因:由于我使用的是Springboot2.2.5版本,其默认使用的mysql-connector-java架包为高版本8.0.19,数据库和系统时区差异
解决:在路径后加?serverTimezone=UTC