zoukankan      html  css  js  c++  java
  • springboot application.properties不生效

    早上上班以后,项目无论如何就是运行不起来,一直提示各种错误。后来一路排查发现是application.properties没有生效导致的。本篇文章记录一下排查过程。

    开始一直提示 Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured.

    完整错误提示如下:

    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).

    根据提示像是DataSource.url没配的原因。但是很确定的是配置DataSource url了的。于是就想着重新运行一下试试,仔细观察了一下idea控制台输出日志,发现居然连port也编程默认的8080了,但是application.properties配置的是8002。这就算是定位到问题了,说明application.properties没有生效。看了一眼target文件夹,application.properties文件没有被自动复制到target文件夹下。

    原因分析:

    1.想着会不会是谁不小心把pom里的packaging给设置错了,可以将设置一下,改成jar。很快这个被推翻了,因为并没有改动。

    2.想着还可能是谁不小心在子module里面又加了一个module,虽然remove,delete,但是modules标签与还在pom还在的原因。但是看了一下也不是这个原因。

    3.想着会不会是谁不小心把pom的build->resource->include的规则给改了,于是在maven的pom.xml重新声明include规则。改完以后运行试一下。发现好了。

    解决方案:

    在maven 的pom.xml下增加这段即可:

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

    https://github.com/toutouge/javademosecond/tree/master/hellospringboot


    作  者:请叫我头头哥
    出  处:http://www.cnblogs.com/toutou/
    关于作者:专注于基础平台的项目开发。如有问题或建议,请多多赐教!
    版权声明:本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接。
    特此声明:所有评论和私信都会在第一时间回复。也欢迎园子的大大们指正错误,共同进步。或者直接私信
    声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是作者坚持原创和持续写作的最大动力!

  • 相关阅读:
    Java Project和Web Project 区别
    ScannerTest-------double string
    ScannerDemo------string int
    clearfix 清除浮动的标签
    bootstrap 的布局
    <span>元素
    反省
    Django中ifequal 和ifnotequal的使用
    IndexError: list index out of range的错误原因
    python2和python3同时存在电脑时,安装包时的的命令行
  • 原文地址:https://www.cnblogs.com/toutou/p/application_properties.html
Copyright © 2011-2022 走看看