• SpringBoot 项目不加载 application.properties 配置文件


    起因:新安装的idea第一次运行springboot项目报url错误(Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.),配置文件application.properties中的代码都是灰色的,而且配置文件的图标也不是绿叶子


    推测原因是未扫描(没有找到)到这个配置文件

    一顿百度之后,借用该帖子(https://www.cnblogs.com/toutou/archive/2019/08/31/embedded-datasource.html)的第四种方法

    yml或者properties文件没有被扫描到,需要在pom文件中<build></build>添加如下.来保证文件都能正常被扫描到并且加载成功.
    <!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉。 -->
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.yml</include>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.yml</include>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
    </resources>

    加了之后读取到配置文件了但是访问html页面404
    去掉这段代码之后再次运行既可以读取到配置文件又可以访问html页面

    可能是idea反应过来了

    再次创建项目就不会出现这种读取不到配置文件的现象

    如果要用到MyBatis可以在pom文件中<build></build>添加如下

      <build>
            <resources>
                <resource>
                    <directory>src/main/java</directory>
                    <includes>
                        <include>**/*.xml</include>
                    </includes>
                </resource>
            </resources>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    

      

    另外再记录一下yml配置文件不识别的解决方法,博客地址:https://blog.csdn.net/qq_40036754/article/details/100578695

  • 相关阅读:
    shell if 条件语句实践
    shell函数
    透视财富增长的秘密
    kvm虚拟化实践
    Linux驱动编程--基于I2C子系统的I2C驱动
    Makefile中=、:=、+=、?=的区别
    字符设备驱动结构与开发
    驱动分类
    为什么ARM的frq中断的处理速度比较快
    Linux设备驱动01
  • 原文地址:https://www.cnblogs.com/wwct/p/12258984.html
Copyright © 2020-2023  润新知