If you want an embedded database (H2, HSQL or Derby), please put it on the classpath

***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified and no embedded datasource could be auto-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).

Process finished with exit code 1

在使用IDEA整合spring cloud項目時,爲了測試負載均衡及提供者與使用者通信是否能夠成功的時,所以先創建了一個提供者producer1,並且整合了mybatis和druid,測試成功後,直接複製了producer1粘貼了一個producer2出來,然後改了下項目名和pom的項目名後,當我要測試FeignClient的負載均衡時,啓動producer2時,發現註冊中心,producer2沒有註冊進去,在仔細看日誌,發現出現瞭如上錯誤。奇怪,一模一樣的 咋就出現差異了??,順便對比了下modules裏producer1、producer2的spring配置,乍一看 沒錯,準備關掉的時候,發現突然發現不一樣:如下:
在這裏插入圖片描述
突然發現producer2下面沒有這個,這丫不是更本沒找到配置文件嘛··。
然後就發現我的resource文件夾idea沒有標示爲resource特有的文件夾 ,尷尬。在選中resource右鍵make directory as =>resource後,在啓動就可以了,這只是其中一種解決辦法哈,順便貼個別人的 這裏供參考
另外注意spring boot 配置文件在resource設置正確的情況下,會顯示成綠色樹葉的圖標。這樣,主要還是之前沒有特別留意到這個配置沒有變成這種圖標。
在這裏插入圖片描述
順便在貼一個我的pom配置,並沒有註釋掉pom裏的東西,也沒有在啓動類上加東西。
解決的話 留下贊?

<properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Greenwich.SR1</spring-cloud.version>
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-autoconfigure</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-commons</artifactId>
            <version>RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- 數據庫連接 -->
        <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.15</version>
        </dependency>
        <!-- 連接池 -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId> <!--druid-spring-boot-starter-->
            <version>1.1.10</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>2.0.0</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.0.0</version>
        </dependency>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章