小编ppb*_*ppb的帖子

docker-entrypoint-initdb.d 错误解释器:权限被拒绝

您好,我在我的应用程序中使用postgres docker-compose。当我尝试在本地计算机(macOS Big Sur)上运行它时,出现以下错误并且postgres容器已退出。

 /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/postgres-ssl.sh
/usr/local/bin/docker-entrypoint.sh: /docker-entrypoint-initdb.d/postgres-ssl.sh: /bin/bash: bad interpreter: Permission denied
Run Code Online (Sandbox Code Playgroud)

下面是我的docker-compose

postgres:
build:
  context: ./setup/postgres
  dockerfile: ./Dockerfile
command:
  -c ssl=on -c ssl_cert_file=/var/lib/postgresql/ssl/certs/server.crt
  -c ssl_key_file=/var/lib/postgresql/ssl/certs/server.key
  -c ssl_ca_file=/var/lib/postgresql/ssl/certs/root.crt
ports:
  - '5432:5432'
volumes:
  - ./setup/postgres/scripts:/docker-entrypoint-initdb.d
environment:
  - POSTGRES_HOST_AUTH_METHOD=trust
Run Code Online (Sandbox Code Playgroud)

我这里缺少任何步骤吗?

postgresql docker-compose

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

模拟 Instant.now() 而不使用 Clock 进入构造函数或不使用 Clock 对象

我的方法之一中有以下代码

ZonedDateTime current = Instant.now().atZone(ZoneId.of(AMERICA_NEW_YORK));
Run Code Online (Sandbox Code Playgroud)

我想current在 JUnit 测试中进行模拟。

我尝试过,java.time.Clock但为此,我需要将其添加到类构造函数中,因为我的代码写入旧版本的 Spring 并使用基于 XML 的配置,此类会导致问题,因为它需要 application-context.xml 文件中的构造函数参数,如果我使用构造函数与Clock.

有没有办法避免current上面代码中的构造函数配置和模拟。

更新

根据帕维尔·斯米尔诺夫的评论,我在下面尝试过,但current仍然返回今天的日期,但不是我嘲笑的日期。

ZonedDateTime exactOneDay = ZonedDateTime.parse("Sun Oct 21 12:30:00 EDT  2018", Parser); 
doReturn(exactOneDay).when(spyEmployeeHelper).getCurrentTime();
employee = getEmployees().get(0);
assertEquals(Integer.valueOf(1), employee.getNoticePeriod());
Run Code Online (Sandbox Code Playgroud)

java junit java-8

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

Java 8从HashMap中提取非null和非空值

让我们考虑一下 HashMap

HashMap<String, String> map = new HashMap<String, String>();
Run Code Online (Sandbox Code Playgroud)

我在地图中有值

map.put("model", "test");
Run Code Online (Sandbox Code Playgroud)

目前,如果我想从我正在做的地图中获取价值

if(map!=null){
 if(map.get("model")!=null && !map.get("model").isEmpty()){
   //some logic
 }
}
Run Code Online (Sandbox Code Playgroud)

通过使用Optional或Lambdas来实现上述条件,Java 8中是否有更好的方法?

java dictionary optional java-8

13
推荐指数
2
解决办法
6856
查看次数

在 swagger ui 中隐藏一些 api

是否可以在 hapi-swagger 中根据用户角色从文档(swagger ui)中隐藏一些 API。我的意思是想我有/employee/admin两个API所以每当管理员登录招摇UI或招摇文档,以便既/employee/adminAPI应该在页面上显示,如果员工登录招摇的用户界面,那么它应该只显示/employeeAPI。

node.js swagger-ui hapijs hapi-swagger

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

创建名为“compositeCompatibilityVerifier”的 bean 时出错

我正在使用Spring Boot 2.5.5with Spring Cloud Version 2020.0.4,但是当我尝试运行该应用程序时,我遇到了异常 -

Exception encountered during context initialization - cancelling refresh attempt:     
org.springframework.beans.factory.BeanCreationException: Error creating bean with name  
'compositeCompatibilityVerifier' defined in class path resource [org/springframework 
/cloud/configuration/CompatibilityVerifierAutoConfiguration.class]: Bean instantiation  
via factory method failed; nested exception is 
org.springframework.beans.BeanInstantiationException: Failed to instantiate 
[org.springframework.cloud.configuration.CompositeCompatibilityVerifier]: Factory 
 method 'compositeCompatibilityVerifier' threw exception; nested exception is 
 org.springframework.cloud.configuration.CompatibilityNotMetException
Run Code Online (Sandbox Code Playgroud)

pom.xml

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

<properties>
    <java.version>1.8</java.version>
    <spring-cloud.version>2020.0.4</spring-cloud.version>
</properties>

<dependencies>
    <!-- Below jar file also …
Run Code Online (Sandbox Code Playgroud)

spring-boot

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

CompletableFuture 对象数组的 Null 检查

我正在将 CompletableFuture 用于我的一项服务,如下 -

CompletableFuture<Employee>[] employeeDetails =
        empIds.stream().map(empId ->
            employeeService.employeeDetails(Integer.valueOf(empId))).toArray(CompletableFuture[]::new);
Run Code Online (Sandbox Code Playgroud)

EmployeeService 内部调用返回员工详细信息的 API。

问题是,当该 API 返回 null 或任何异常时,响应将为 null。当我检查 null 时,即使employeeDetails 数组为 null 并且其值也为 null 并且我得到 Null 指针,它也始终为 false。

我正在检查 null 作为 -

if(employeeDetails != null && employeeDetails.length > 0){
   //This condition always true even if null values or null array.
   CompletableFuture<Void> allEmployeeDetails = CompletableFuture.allOf(employeeDetails); // Here I am getting NullPointerException
}
Run Code Online (Sandbox Code Playgroud)

我在这里犯了任何错误,或者 CompletableFuture 数组需要处理任何特殊检查。

java java-8 completable-future

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

验证 Java LocalDate 是否与 yyyy-MM-dd 格式与可读消息匹配

我在 DoB 的 POJO 类中有以下属性。

@NotNull(message = "dateOfBirth is required")
@JsonDeserialize(using = LocalDateDeserializer.class)
LocalDate dateOfBirth;
Run Code Online (Sandbox Code Playgroud)

我怎样才能验证这一点

  1. 用户正在发送有效的日期格式(仅接受 YYYY-MM-DD)
  2. 如果用户输入不正确的日期,我想发送自定义消息或更易读的消息。目前,如果用户输入无效日期,则应用程序会发送以下长错误 -
JSON parse error: Cannot deserialize value of type `java.time.LocalDate` from String \"1984-33-12\": Failed to deserialize java.time.LocalDate:
(java.time.format.DateTimeParseException) Text '1984-33-12' could not be parsed: Invalid value for MonthOfYear (valid values 1 - 12): 33; 
...
Run Code Online (Sandbox Code Playgroud)

java jackson bean-validation jackson-databind

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

formik 警告,组件正在更改要控制的文本类型的不受控制的输入

我正在 React Web 中开发动态,当用户点击添加按钮注册表单被添加到屏幕时。在注册表中,我使用 formik 集成进行验证。表单动态添加成功,但是当我开始在输入框中输入任何输入时,我在控制台中遇到以下错误

index.js:1 Warning: A component is changing an uncontrolled input of type text to be controlled. Input elements should not switch from uncontrolled to controlled (or vice versa). Decide between using a controlled or uncontrolled input element for the lifetime of the component. 
Run Code Online (Sandbox Code Playgroud)

我不知道哪里错了。下面是我的动态表单渲染代码 -

账户.js

import React, { Component } from 'react';
import axios from 'axios';
import {Card, CardBody, CardHeader,Button,Col, Row, Form, Container} from 'reactstrap';
import { Formik, Field, ErrorMessage } from 'formik';
import …
Run Code Online (Sandbox Code Playgroud)

react-web formik

5
推荐指数
2
解决办法
6346
查看次数

下一个或后退时,Material UI Stepper 不保持状态

我有Material UI Stepper组件。我在 Buttonstepper上动态渲染ADD。每个步骤都包括一些表格,包括TextFields, SelctBox etc.当我在第一步填写表格并单击下一步在下一个屏幕上填写表格时,如果我通过单击返回第一步,BACK Button我将丢失第一步填写的数据。

所以问题是 - 有没有办法在Form Fields我们改变步骤时保留数据?

我在下面尝试过,但不明白如何在父组件上存储状态。

export default function FeaturesSteppers(props) {

.......
const [stepperState, setStepperState] = React.useState({});

const getStepContent = step => {
switch (step) {
  case 0:
    return <Profile 
      index={index} 
      form={form} 
      stepperState={stepperState}
      onUpdateStepperState={handleUpdateStepper}
    />;
  case 1:
    return "< Step1 />";
  case 2:
    return "< Step2 />";
  case 3:
      return "< Step3 />";
  default:
    return "Unknown step";
}
}

.........

const handleUpdateStepper …
Run Code Online (Sandbox Code Playgroud)

reactjs material-ui

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

ArrayList 和 Arrays.asList() 的 Junit 断言错误

我有返回对象 ArrayList 的方法,如下所示 -

public <Range> getAllRanges(List<Range> ranges){
  //Some business logic
  ....
  List<Range> resultRanges = new ArrayList<>();
  .....
  return resultRanges;
}
Run Code Online (Sandbox Code Playgroud)

我为此编写 Junit 作为 -

@Test
public void someInputTest() {
    final List<Range> ranges = Arrays.asList(new Range(1, 3), new Range(2, 4));
    final List<Range> actual = myCalss.getAllRanges(ranges);
    final List<Range> expected = Arrays.asList(new Range(1, 4));
    assertEquals(expected, actual);
}
Run Code Online (Sandbox Code Playgroud)

但我收到断言错误,例如 -

java.lang.AssertionError: expected: java.util.Arrays$ArrayList<[(1, 4)]> but was: java.util.ArrayList<[(1, 4)]>
....
Run Code Online (Sandbox Code Playgroud)

之后我在测试中尝试了下面的代码 -

@Test
public void someInputTest() {
    final List<Range> ranges = Arrays.asList(new Range(1, 3), …
Run Code Online (Sandbox Code Playgroud)

java junit

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

Hapi-Swagger 因标头值而失败

我在我们的应用程序中使用 hapi-swagger,其中一个 API 尝试使用自定义标头,但是当我使用自定义标头调用该 API 时出现以下错误

{
"statusCode": 400,
"error": "Bad Request",
"message": "Invalid request headers input"
}
Run Code Online (Sandbox Code Playgroud)

在我使用带有验证器的标头的 API 下方。

{
        method: 'POST',
        path: '/v1/testapi',
        config: {
            description: 'Greet user',
            notes: ['Use to greet a user'],
            tags: ['api'],    
            handler: function ( request, h ) {
                console.log('sending response...');
                return h.response('OK');
            },
            validate: {
                headers: {
                    name: Joi.string().required()
                }
            }                               
        }
    }
Run Code Online (Sandbox Code Playgroud)

以下是我们正在使用的版本。

"hapi": "17.2.2",

"hapi-swagger": "9.1.1",

"joi": "13.1.2",

node.js swagger-ui hapijs hapi-swagger

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

Spring Boot 中 JSON 字段反序列化为小写

我有一个Spring Boot Controller-

@RestController
public class UserController {

   @PostMapping
   @ResponseStatus(CREATED)
   public UserResponse register( @Valid @RequestBody UserRequest userRequest) {
     //return ....
   } 
}
Run Code Online (Sandbox Code Playgroud)

下面是UserRequest.java

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class UserRequest {

    private String email;
    //other property
}
Run Code Online (Sandbox Code Playgroud)

我在请求正文中发送以下 json -

 {
   "email" : "TEST@Example.com",
   //some other fields.
 }
Run Code Online (Sandbox Code Playgroud)

有时客户端email以大写或驼峰形式发送,因此userRquest我想将email字段的值更改为小写,就像test@example.com反序列化为UserRequest对象时一样。

有没有什么简单的方法可以做到这一点。我可以介绍我自己的注释annotation吗,比如@ToLowerCase如何创建自己的注释并在UserRequest.

jackson java-8 spring-boot jackson-databind

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

避免在条件中出现多个OR语句的更好方法

有没有更好的办法,以避免重复OR的语句if条件?我有if超过8个字符串的OR语句。

if(type.equalsIgnoreCase(anotherString1) ||   
   type.equalsIgnoreCase(anotherString2) ||   
   type.equalsIgnoreCase(anotherString3)){
    return true;
}
Run Code Online (Sandbox Code Playgroud)

寻找更好的方法来编写if多条OR语句或如何避免

java

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