我正在尝试在Spring Boot中使用非嵌入式PostgreSQL数据库。但是当我尝试运行我的应用程序“mvn spring-boot:run”时,应用程序无法启动以下消息:
无法确定数据库类型为NONE的嵌入式数据库驱动程序类
这些是我对pom.xml的依赖:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
</dependency>
<dependency>
<!-- Eureka service registration -->
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
<dependency>
<!-- Spring Cloud starter -->
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-jwt</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
<version>${mapstruct.version}</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4-1206-jdbc42</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.0.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.pew.common</groupId>
<artifactId>backend-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.6.RELEASE</version>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>spring-mock-mvc</artifactId>
<version>3.0.2</version>
<scope>test</scope>
</dependency>
</dependencies>
这是我在application.yml中的设置:
spring:
profiles: dev
application:
name: resource-service
jpa:
database: POSTGRESQL
datasource:
platform: postgres
url: jdbc:postgresql://${postgresqlHost:localhost}:${postgresqlPort:5432}
username: ${postgresqlUsername:root}
password: ${postgresqlPassword:SomePassword}
driverClassName: org.postgresql.Driver
我找不到太多关于此的信息,这让我觉得这可能很容易让人工作......
答案 0 :(得分:0)
您需要正确提供数据库URL和驱动程序类名称
spring.datasource.url = <database source url>
spring.datasource.driver-class-name = <driver class name>
答案 1 :(得分:0)
执行"mvn spring-boot:run"
时,如果要为dev
配置文件配置数据源属性,则不指定使用Spring Boot dev
配置文件:
profiles: dev
此外,在application.yml中,您应该引用该属性:
spring.datasource
而不是jpa.database.datasource
没有被Spring使用。
你应该写:
spring.datasource:
driverClassName: org.postgresql.Driver
url: jdbc:postgresql://${postgresqlHost:localhost}:${postgresqlPort:5432}
...
Here是关于如何做的文档参考。