数据源:未指定“url”属性,无法配置嵌入式数据源
Posted
技术标签:
【中文标题】数据源:未指定“url”属性,无法配置嵌入式数据源【英文标题】:DataSource: 'url' attribute is not specified and no embedded datasource could be configured 【发布时间】:2019-09-12 18:58:52 【问题描述】:我正在服务器上开发 Spring Boot,并在前端使用 mysql 做出反应。
当我启动我的应用程序时,我收到以下错误。
关于这个问题的任何指针?
应用程序启动失败
说明:
配置数据源失败:未指定“url”属性,无法配置嵌入式数据源。
原因:无法确定合适的驱动程序类
行动:
考虑以下几点: 如果您想要一个嵌入式数据库(H2、HSQL 或 Derby),请将其放在类路径中。 如果您有要从特定配置文件加载的数据库设置,您可能需要激活它(当前没有激活的配置文件)。
进程以退出代码 1 结束
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fr.alexisvachard</groupId>
<artifactId>authentication-poc</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>authentication-poc</name>
<description>JWT Authentication poc</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<jjwt.version>0.9.1</jjwt.version>
<swagger.version>2.9.2</swagger.version>
<swagger-ui.version>2.9.2</swagger-ui.version>
<aerogear-otp-java.version>1.0.0</aerogear-otp-java.version>
<zxing-core.version>3.3.3</zxing-core.version>
<zxing-javase.version>3.3.3</zxing-javase.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>$jjwt.version</version>
</dependency>
<dependency>
<groupId>com.warrenstrange</groupId>
<artifactId>googleauth</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>$zxing-core.version</version>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>javase</artifactId>
<version>$zxing-javase.version</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>$swagger.version</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>$swagger-ui.version</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
应用程序-dev.properties
#-Dspring.profiles.active=dev
### SERVER PROPERTIES
server.address=localhost
server.port=8080
### SPRING DATASOURCE PROPERTIES
spring.datasource.url=jdbc:mysql://localhost:3306/blog
spring.datasource.username=root
spring.datasource.password=123
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
### HIBERNATE PROPERTIES
spring.jpa.database-platform = org.hibernate.dialect.MySQL5Dialect
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto = update
### JACKSON PROPERTIES
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false
spring.jackson.date-format=dd-MM-yyyy
### LOG PROPERTIES
logging.level.fr.alexisvachard.authenticationpoc=TRACE
logging.file=authentication-poc.log
### APPLICATION PROPERTIES
fr.alexisvachard.authentication-poc.app.front.host=http://localhost:3000
fr.alexisvachard.authentication-poc.jwt.secret=
fr.alexisvachard.authentication-poc.jwt.expirationInMs=604800000
fr.alexisvachard.authentication-poc.jwt.rememberMeExpirationInMs=2592000000
fr.alexisvachard.authentication-poc.cors.maxAge=3600
fr.alexisvachard.authentication-poc.email.from=
fr.alexisvachard.authentication-poc.email.template-base-package=/mailTemplate
### EMAIL PROPERTIES
spring.mail.host=
spring.mail.username=
spring.mail.password=
spring.mail.properties.mail.transport.protocol=
spring.mail.properties.mail.smtp.port=
spring.mail.properties.mail.smtp.auth=
spring.mail.properties.mail.smtp.starttls.enable=
spring.mail.properties.mail.smtp.starttls.required=
spring.mail.properties.mail.smtp.ssl.trust=
spring.mail.default-encoding=UTF-8
spring.mail.port=
## ACTUATOR SETTINGS
management.endpoints.enabled-by-default=false
management.endpoint.health.enabled=true
management.endpoint.httptrace.enabled=true
management.endpoint.metrics.enabled=true
management.endpoints.web.base-path=/manage
management.endpoint.health.roles=ROLE_ADMIN
management.endpoint.health.show-details=when_authorized
management.endpoints.web.cors.allowed-origins=*
management.endpoints.web.cors.max-age=3600s
management.endpoints.web.cors.allowed-headers=*
management.endpoints.web.cors.allowed-methods=GET
management.endpoints.web.exposure.include=health, httptrace, metrics
应用程序-prod.properties
#-Dspring.profiles.active=prod
### SERVER PROPERTIES
server.address=localhost
server.port=8080
### SPRING DATASOURCE PROPERTIES
spring.datasource.url=jdbc:mysql://localhost:3306/blog
spring.datasource.username=root
spring.datasource.password=123
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
### HIBERNATE PROPERTIES
spring.jpa.database-platform = org.hibernate.dialect.MySQL5Dialect
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto = update
### JACKSON PROPERTIES
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false
spring.jackson.date-format=dd-MM-yyyy
### LOG PROPERTIES
logging.level.fr.alexisvachard.authenticationpoc=TRACE
logging.file=authentication-poc.log
### APPLICATION PROPERTIES
fr.alexisvachard.authentication-poc.app.front.host=http://localhost:3000
fr.alexisvachard.authentication-poc.jwt.secret=
fr.alexisvachard.authentication-poc.jwt.expirationInMs=604800000
fr.alexisvachard.authentication-poc.jwt.rememberMeExpirationInMs=2592000000
fr.alexisvachard.authentication-poc.cors.maxAge=3600
fr.alexisvachard.authentication-poc.email.from=
fr.alexisvachard.authentication-poc.email.template-base-package=/mailTemplate
### EMAIL PROPERTIES
spring.mail.host=
spring.mail.username=
spring.mail.password=
spring.mail.properties.mail.transport.protocol=
spring.mail.properties.mail.smtp.port=
spring.mail.properties.mail.smtp.auth=
spring.mail.properties.mail.smtp.starttls.enable=
spring.mail.properties.mail.smtp.starttls.required=
spring.mail.properties.mail.smtp.ssl.trust=
spring.mail.default-encoding=UTF-8
spring.mail.port=
## ACTUATOR SETTINGS
management.endpoints.enabled-by-default=false
management.endpoint.health.enabled=true
management.endpoint.httptrace.enabled=true
management.endpoint.metrics.enabled=true
management.endpoints.web.base-path=/manage
management.endpoint.health.roles=ROLE_ADMIN
management.endpoint.health.show-details=when_authorized
management.endpoints.web.cors.allowed-origins=*
management.endpoints.web.cors.max-age=3600s
management.endpoints.web.cors.allowed-headers=*
management.endpoints.web.cors.allowed-methods=GET
management.endpoints.web.exposure.include=health, httptrace, metrics
【问题讨论】:
【参考方案1】:您使用什么命令来运行应用程序?
我注意到您有两个配置文件:dev 和 prod。
如果您在没有配置文件的情况下运行应用程序,Spring Boot 您会“寻找”默认值,并且您似乎没有默认属性文件。
更多信息:https://www.baeldung.com/spring-profiles
【讨论】:
以上是关于数据源:未指定“url”属性,无法配置嵌入式数据源的主要内容,如果未能解决你的问题,请参考以下文章
Spring:无法配置数据源:未指定“url”属性,并且无法配置嵌入式数据源[关闭]
无法配置数据源:未指定“url”属性,并且无法配置嵌入式数据源。原因:发
无法配置数据源:未指定“url”属性,无法配置嵌入式数据源。- java spring 项目