Maven资源过滤问题

2022-11-23 18:04:50 浏览数 (2)

遇到的问题:扫描不到 yaml 配置文件

报错: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

原因:maven资源过滤问题

解决方式

添加如下代码:(注意区别,这里的资源过滤 添加了对yml /yaml格式文件的支持

代码语言:javascript复制
<build>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
                <include>**/*.yml</include>
                <include>**/*.yaml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
                <include>**/*.yml</include>
                <include>**/*.yaml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
    </resources>
</build>

当资源成功被扫描到后,在运行之后会在输出目录生成相应的文件,如下图:

0 人点赞