springboot使用过程问题整理

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版本选上
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Zzzz_zzzz_zz

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值