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

问题:一个脑袋两个大

1.将Springboot项目打包成war包

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

       1.2 配置pom.xml文件

                     1.2.1 配置成war包

                                

     代码:

<packaging>war</packaging>

                    1.2.2 添加依赖

                                

代码:

<!--避免打包时与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包粘贴进去如图:

                                                    

           配置pom.xml

       

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

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

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

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

           2. 打包成war包

                                                   

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

 

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改变时区设置

                        

输入代码:

SHOW VARIABLES LIKE '%time_zone%';

如图:

                                 

再输入:

SET GLOBAL time_zone='+8:00';

即可解决

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

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

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

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

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

l8947943

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

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

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

打赏作者

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

抵扣说明:

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

余额充值