问题:一个脑袋两个大

1.将Springboot项目打包成war包

       1.1首先保证你项目可以run起来不报错

SpringBoot+mybatis搭建项目出现的各种坑_jar包

       1.2 配置pom.xml文件

                     1.2.1 配置成war包

                                

SpringBoot+mybatis搭建项目出现的各种坑_spring_02

     代码:

<packaging>war</packaging>

                    1.2.2 添加依赖

                                

SpringBoot+mybatis搭建项目出现的各种坑_jar包_03

代码:

<!--避免打包时与tomcat容器冲突-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!--添加maven插件-->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
</dependency>

1.2.3 这一步是为了解决maven项目有jar包情况解决的,如果各位看官没有给maven项目增加jar包,则可以跳过本步骤

           由于maven仓库中没有我需要的几个jar包,我单独下载并导入到项目,正常可以启动起来,但是打包成war包却提示出错找不到jar包,这是因为打包需要将jar包添加成依赖。做法如下:

          在自己项目中新建一个lib文件夹,将自己需要的jar包粘贴进去如图:

                                                    

SpringBoot+mybatis搭建项目出现的各种坑_jar包_04

           配置pom.xml

       

SpringBoot+mybatis搭建项目出现的各种坑_spring_05

                             1部分是为了让范围打开,各种构建都允许,如果前面每个依赖都有scope这个可以不要

                             2是为了找到path路径去找包的

          再添加依赖,举一个例子:

SpringBoot+mybatis搭建项目出现的各种坑_war包_06

画红线处是必须的,填完这两个信息,其他会自动有groupId可以随意,此处表示我引入lucene-analyzers-....这个jar包,并会在打包成war包时候会自动引入,其他同理

           2. 打包成war包

                                                   

SpringBoot+mybatis搭建项目出现的各种坑_war包没spring_07

                                               构建过程如图:出现success表示成功,如果没有,则进行踩坑

SpringBoot+mybatis搭建项目出现的各种坑_spring问题_08

 

2.将Springboot项目打包成war不成功,报错

   2.1 报错信息:

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class


Action:

Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

    2.2解决方法:配置datasource,找到application.yml

spring:
datasource:
name: test
url: jdbc:mysql://localhost:3306/searchenginee?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver

 原因:报错表示缺少数据源,因为你在一开始建立项目点击了依赖Mybatis,因此缺少数据源会报错,正常添加数据源配置就ok

3 .报错Mysql问题

  3.1 报错信息

The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone.

   3.2解决方法:进入mysql改变时区设置

                        

SpringBoot+mybatis搭建项目出现的各种坑_jar包_09

输入代码:

SHOW VARIABLES LIKE '%time_zone%';

如图:

                                 

SpringBoot+mybatis搭建项目出现的各种坑_jar包_10

再输入:

SET GLOBAL time_zone='+8:00';

即可解决

4 .打包成的war包放入到tomcat中,启动访问并没有Spring字样,等于没有启动成功

      4.1 无报错信息,访问Controller的路由显示404

       4.2 解决方法:在application启动入口继承SpringBootServletInitializer,如图:

SpringBoot+mybatis搭建项目出现的各种坑_war包_11

       4.3 原因:不是很理解,但是解决了,感觉是因为继承有了spring的程序入口