記錄SpringBoot的相關報錯信息html
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency>
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
source : http://www.javashuo.com/article/p-cncvuqvs-bw.htmljava
緣由mysql
1. DataSourceAutoConfiguration會自動加載. 2. 沒有配置spring - datasource - url 屬性. 3. spring - datasource - url 配置的地址格式有問題. 4. 配置 spring - datasource - url的文件沒有加載.
解決spring
方案一 (解決緣由1)[本人就是這種狀況] 排除此類的autoconfig。啓動之後就能夠正常運行。 @SpringBootApplication(exclude= {DataSourceAutoConfiguration.class}) 方案二 (解決緣由2) 在application.properties/或者application.yml文件中沒有添加數據庫配置信息. spring: datasource: url: jdbc:mysql://localhost:3306/read_data?useUnicode=true&characterEncoding=UTF-8&useSSL=false username: root password: 123456 driver-class-name: com.mysql.jdbc.Driver 方案三 (解決緣由3) 在spring xml配置文件中引用了數據庫地址 因此須要對:等進行轉義處理.可是在application.properties/或者application.yml文件並不須要轉義,錯誤和正確方法寫在下面了. //錯誤示例 spring.datasource.url = jdbc:mysql\://192.168.0.20\:1504/f_me?setUnicode=true&characterEncoding=utf8 //正確示例 spring.datasource.url = jdbc:mysql://192.168.0.20:1504/f_me?setUnicode=true&characterEncoding=utf8 方案四 (解決緣由4) 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>