1、 Application启动类注意不可以直接放在java文件夹下,需要放在java的下层目录下
2、 mybatis遇到以下错误
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.
出现了mysql的无效连接属性异常:服务器时区值无法辨认或表示多个时区,如果你想使用时区支持,你必须通过服务器时区配置属性来配置服务器或JDBC驱动从而使用更具体的时区值。
原因是因为MySQL版本过高,MySQL升级到8.0及以上,添加了许多新特性,安全性也得到提升。当然操作时也增加了些繁琐,需要考虑到的时区问题便是其中之一。
解决办法:
1、url 部分加上 serverTimezone=UTC
2、url 部分加上 serverTimezone=Asia/Shanghai
3、或者在url路径的问号后面加上:useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC,也可以解决问题.
3、 使用不同SpringBoot版本,指定访问项目路径的项目名,使用的配置也不一样,博主也不例外的跳进了坑。
以下是两种配置方式:
SpringBoot版本 配置
1.x server.context-path=/demo
2.x server.servlet.context-path=/demo
4、 spring boot使用tomcat部署
在springboot中,内嵌tomcat服务器,也默认使用main函数启动整个项目
1、tomcat容器里面运行的是war,而spring boot默认生成的是jar包,所以需要先把jar包的打包方式改成war包
在pom文件中添加
<packaging>war</packaging>
2、springboot里面会内置一个tomcat容器,如果再加入tomcat容器中会出错,所以先要去除内置tomcat
在pom文件中添加
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
或者将pom文件中
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
替换成下面的代码
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!-- 移除嵌入式tomcat插件 -->
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
3、修改启动类,在spring boot中项目启动是通过main方法启动的,而使用外置tomcat是通过web.xml方式启动,所以要修改该启动类
@SpringBootApplication
public class GovServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
}
5、启动报错:Unable to start embedded Tomcat
如下图:给jdk版本选上