SpringBoot啓動報錯: Failed to configure a DataSource: url attribute is not specified and no embedded

 問題描述:

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

原因是(我的情況):

項目中引入了外部jar包,然後在pom文件中,增加jar包路徑的指引,應該是因爲單獨配置了jar包路徑,然後springboot默認配置文件全走路徑指引了,所以在pom文件中在增加對配置文件的路徑指引就可以

<resource>
	            <directory>lib</directory>
	            <targetPath>BOOT-INF/lib/</targetPath>
	            <includes>
	                <include>**/*.jar</include>
	            </includes>
	        </resource>
	        <resource>
	            <directory>src/main/resources</directory>
	            <targetPath>BOOT-INF/classes/</targetPath>
	        </resource>

這是我配置jar包的路徑.

解決方法就是如下配置:

pom文件中增加對配置文件的路徑指引

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

 

這個問題只在本地運行時出現了,因爲線上部署的時候是吧配置文件放在jar包同級目錄了,然後就不會出現找不到配置文件的問題.原因可以搜索一下<springboot的配置文件加載優先級>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章