如何使用CockroachDB和Spring-Boot解决密码问题

时间:2019-09-03 12:17:36

标签: postgresql spring-boot liquibase cockroachdb

spring-boot和cockroachDB出现问题。在我的本地计算机上运行cockraochDB和spring-boot。春季启动一开始,我就会例外。蟑螂在不安全的模式下运行。

application.yaml:

spring:
  datasource:
    url: jdbc:postgresql:localhost:26257/mydb?sslmode=disable
    username: myuser
    password: 
  jpa:
      properties:
         hibernate.dialect: org.hibernate.dialect.PostgreSQL94Dialect
      show-sql: true
      database-platform: org.hibernate.dialect.PostgreSQL94Dialect
      hibernate:
         ddl-auto: create

pom.xml部分:

[...]
    <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-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>
        <dependency>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-maven-plugin</artifactId>
            <version>3.4.1</version>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
        </dependency>
    </dependencies>
[...]

我创建了两个用户。一种没有密码,另一种没有密码的是cockroachDB上的数据库“ mydb”。两者都不起作用。在spring.datasource.url中的网址上附加“?sslmode = disable”也无效。

没有密码的异常:

org.postgresql.util.PSQLException: The server requested password-based authentication, but no password was provided.

密码异常:

Caused by: org.postgresql.util.PSQLException: FATAL: password authentication failed for user "myuser"

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

您必须在数据源URL中的postgressql之后使用://

您的数据源网址应为

jdbc:postgresql://localhost:26257/mydb?sslmode=disable