小编Jav*_*ano的帖子

Spring Boot 中的 PostgreSQL 失败

我有一个新的 Spring Boot 应用程序,我试图将它插入到我的本地 PostgreSQL 实例中,但是我遇到了驱动程序故障。我有一个基本的驱动程序类设置如下:

package com.rainydaymatt.lfgenie.lfgenieapi;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class LfgenieApiApplication {

    public static void main(String[] args) {
        SpringApplication.run(LfgenieApiApplication.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

我决定暂时放弃 .yml 配置,转而使用默认的 application.properties 文件,并使用我能找到的 Spring Boot 的少量 PSQL 内容将其拼凑在一起:

spring.datasource.url=jdbc:postgresql://localhost:15432/harpm
spring.datasource.username=admin
spring.datasource.driver-class-name=org.postgresql.Driver
Run Code Online (Sandbox Code Playgroud)

然后将持久性 PostgreSQL 实例的依赖项添加到 Initializr 构造的 pom 中,如下所示:

<groupId>com.rainydaymatt.lfgenie</groupId>
<artifactId>lfgenie-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>lfgenie-api</name>
<description>Demo project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.9.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency> …
Run Code Online (Sandbox Code Playgroud)

java postgresql spring maven spring-boot

4
推荐指数
2
解决办法
2万
查看次数

驱逐 EhCache 中的所有元素

我正在将 EhCache 与 spring 一起使用,并且需要公开一个端点,该端点将驱逐给定 EhCache 中的所有元素。但是我找不到任何驱逐所有元素的方法。这是微不足道的,可能已经讨论过了,但我在互联网上找不到任何资源。请提供指点。

java spring ehcache spring-cache

2
推荐指数
1
解决办法
2043
查看次数

Spring boot 中的自定义表单验证

我正在开发一个 Spring Boot 应用程序,并且有一个密码重置表单。我正在使用这样的类来验证输入。

public class PasswordResetForm {

    @NotEmpty
    @Size(min=6, message="must be at least 6 characters")
    private String password;

    private String passwordConfirm;

    //Getter and Setters
}
Run Code Online (Sandbox Code Playgroud)

因此,我现在想要验证字段“passwordConfirm”和“password”是否相等,我进行了全面搜索,但找不到如何在这种情况下添加自定义验证。那么,如何为其他字段添加自定义验证呢?

我的控制器的动作看起来像这样

@RequestMapping(value = "/password-change/{id}-{tokenNumber}", method = RequestMethod.POST)
public String changePassword(@PathVariable String id, @PathVariable String tokenNumber, @Valid PasswordResetForm form, BindingResult formBinding, Model model) {

    if (formBinding.hasErrors())
        return "change-password";

    //Other stuff
}
Run Code Online (Sandbox Code Playgroud)

custom-validators bean-validation spring-boot

1
推荐指数
1
解决办法
5450
查看次数