坑一:资源过滤问题
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,他都不会把没写的文件加入进去,也就是,不会默认编译你写的前端页面了,如图:
结果就是,运行的时候,找不到页面了。。。
直接删除这个吧,有用的时候再加上。