记录一下Spring Boot整合Mybatis遇到的坑。。。

坑一:资源过滤问题

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).
2021-11-12 20:17:39.428 ERROR 14932 --- [           main] o.s.test.context.TestContextManager      : Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener@4b741d6d] to prepare test instance [com.ztm.S16FuwenbenApplicationTests@41ffaeb8]
java.lang.IllegalStateException: Failed to load ApplicationContext

但整合了Mybatis确实写了url,如下图:
在这里插入图片描述
这个配置确实没什么毛病。
原因出在了环境上,就是pom文件中,多写了个编译的配置项,整了一下午,终于被我发现了!!!如下:
在这里插入图片描述
发现这么写,编译后项目中完全没有看到任何xml文件和yml文件,如图:
在这里插入图片描述
将resources删除,就可以顺利运行了。
百度了一下,说这么写是为了解决资源过滤的问题,但是无论是改成true还是false都不好用。查看了网友的,发现原来是少写了一resources下的内容,改为如下配置,可以解决:

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>

        <!--文件过滤问题,表示过滤掉xxx文件-->
        <resources>

            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.yml</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.yml</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>
    </build>

这样编译后,发现编译后的项目中多了yml配置文件
在这里插入图片描述
程序可以顺利运行。
改为true试试:发现项目仍可正常编译。
在这里插入图片描述
感觉true和false都会编译这些配置文件。。。
但是,无论是true还是false,他都不会把没写的文件加入进去,也就是,不会默认编译你写的前端页面了,如图:
在这里插入图片描述
结果就是,运行的时候,找不到页面了。。。
在这里插入图片描述
直接删除这个吧,有用的时候再加上。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值