小编Rah*_*hul的帖子

@NotNull 注释在 Spring 启动应用程序中不起作用

下面是我的 DTO 课程。

public class AbstractDTO extends BaseDTO {

    private Integer createdBy;

    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = DATE_FORMAT)
    @NotNull(message = "createdDate may not be null")
    private LocalDateTime createdDate;

    private Integer lastModifiedBy;
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = DATE_FORMAT)
    private LocalDateTime lastModifiedDate;

    private Boolean isActive;

    // getter & setters
}
Run Code Online (Sandbox Code Playgroud)

在这里,我试图将 createdDate 字段注释为 @NotNull 但它不起作用。它允许在请求正文中并且在邮递员中执行服务后没有收到任何错误。

我尝试了以下选项,但没有运气。

1)尝试添加maven依赖。

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

2) 尝试将 DTO 类注释为 @Validated

3) 尝试使用 @NotNull 注释 createdDate 字段 @Valid 但仍然没有运气。

请帮我解决这个问题。

java spring spring-mvc spring-boot

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

keycloak 中基于 SMS 的 OTP 是可能的吗?

我正在探索 keycloak,我想构建一个基于用户手机号码的应用程序,短信 OTP 应该去用户进行身份验证。我找不到任何地方。

oauth-2.0 spring-boot keycloak keycloak-services

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

CompletableFuture.runAsync() 的 Mockito 测试用例调用 void 方法

我需要帮助为下面的方法编写模拟测试用例。

public void getCouponAndNotifyAsync(String countryId, String channelId,
        String storeNumber, String clientId, NotificationRequest notificationRequest)
        throws FirestoreException, TurneroServiceException {
    CompletableFuture.runAsync(() -> getCouponAndNotify(countryId, channelId,
            storeNumber, clientId, notificationRequest));
}
Run Code Online (Sandbox Code Playgroud)

其中 getCouponAndNotify() 是一个 void 方法。

尝试了下面但它不起作用

@Test
    public void getCouponAndNotifyAsync() throws Exception {
        //doNothing().when(turneroService).getCouponAndNotify(COUNTRYID, CHANNELID, STORENUMBER, CLIENTID, new NotificationRequest("ext_rborse@falabella.cl", "all"));

        CompletableFuture<Void> runAsync = CompletableFuture
                .runAsync(() -> doNothing().when(turneroService).getCouponAndNotify(COUNTRYID, CHANNELID, STORENUMBER, CLIENTID, new NotificationRequest("ext_rborse@falabella.cl", "all")));

        assertTrue(runAsync.isDone());

    }
Run Code Online (Sandbox Code Playgroud)

更新了测试用例但仍然不起作用。

@Test
    public void getCouponAndNotifyAsync() throws Exception {
        //doNothing().when(turneroService).getCouponAndNotify(COUNTRYID, CHANNELID, STORENUMBER, CLIENTID, new NotificationRequest("ext_rborse@falabella.cl", "all"));

        CompletableFuture<Void> runAsync = CompletableFuture
                .runAsync(() …
Run Code Online (Sandbox Code Playgroud)

java junit mockito java-8 spring-boot

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

无法在 jhipster 中访问 H2 控制台

我无法在网络浏览器上打开 H2 控制台。我的 jhipster 应用程序在 8088 端口上运行。在服务器日志中,我发现 H2 数据库在端口 18088 上可用。

下面尝试过。 http://localhost:18088/h2-console

得到以下回应。 在此输入图像描述

以下是 application-dev.yml 中的详细信息。

devtools:
    restart:
      enabled: true
      additional-exclude: .h2.server.properties
    livereload:
      enabled: false # we use Webpack dev server + BrowserSync for livereload
  jackson:
    serialization:
      indent-output: true
  datasource:
    type: com.zaxxer.hikari.HikariDataSource
    url: jdbc:h2:mem:jhipstersampleapplication;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
    username: jhipsterSampleApplication
    password:
    hikari:
      poolName: Hikari
      auto-commit: false
  h2:
    console:
      enabled: true
  jpa:
    database-platform: io.github.jhipster.domain.util.FixedH2Dialect
    database: H2
    show-sql: true
    properties:
      hibernate.id.new_generator_mappings: true
      hibernate.connection.provider_disables_autocommit: true
      hibernate.cache.use_second_level_cache: true
      hibernate.cache.use_query_cache: false
      hibernate.generate_statistics: false
Run Code Online (Sandbox Code Playgroud)

这个你能帮我吗。

java h2 spring-boot jhipster jhipster-registry

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