彻底解决Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource | 您所在的位置:网站首页 › 怎么解决未指定的url › 彻底解决Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource |
springboot2启动项目报错,应该是数据库连接的问题,导致无法启动。 错误消息如下: *************************** 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).********************************** 第一种,项目不需要连接数据库,启动报错 ****************************************** 解决方法如下: 只要在将@SpringBootApplication修改为@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})就可以启动的时候不需要连接数据库。 @SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})********************************** 第2种,需要连接数据库,启动报错 ****************************************** 解决方法如下: 第一种,yml配置示例如下 #在application.properties/或者application.yml文件中没有添加数据库配置信息. spring: datasource: url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=false username: root password: 123456 driver-class-name: com.mysql.jdbc.Driver第二种,properties文件示例如下 spring.datasource.url = jdbc:mysql://localhost:3306/test?setUnicode=true&characterEncoding=utf8第三种,mysql的版本不同,示例如下 #mysql8以下的版本,请检查pom.xml文件种依赖的mysql jar包的版本 driver-class-name: com.mysql.jdbc.Driver #mysql8以下的url写法 url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=false #mysql8的版本写法,多了个cj driver-class-name: com.mysql.cj.jdbc.Driver #同时mysql8的url也需要加入时区,参照如下 url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&tinyInt1isBit=false第四种,项目没有加载到yml或者properties文件,特别是自己的pom打包是jar的项目,请查看自己的pom.xml文件中的packaging jar如果pom中指定使用jar,系统不会自动读取到yml或者properties文件的,需要我们手动配置pom.xml。 org.springframework.boot spring-boot-maven-plugin src/main/java **/*.yml **/*.properties **/*.xml false src/main/resources **/*.yml **/*.properties **/*.xml false lib **/*.jar第五种,项目使用了springcloud+nacos系列,启动项目时候需要手动指定【--spring.profiles.active=test】,那么在resources文件夹下就必须要有bootstrap-test.yml或者application-test.yml文件,同时配置文件中连接的nacos地址里面也必须配置对应的命名空间,和对应服务名称的yml文件,否则也是报错。下面是配置文件的截图 |
CopyRight 2018-2019 实验室设备网 版权所有 |