小编夢のの*_*のの夢的帖子

添加源请求策略(包括所有标头和查询字符串)时,CloudFront 给出 403?

我正在尝试使用自定义源名称设置 CF 发行版,该发行版指向 Route53 中的自定义域设置,并具有基于延迟的路由(到多个区域)。这是因为区域 API 不包含用户 IP 信息(XFF 标头),而 CloudFront 包含。

在这样做的过程中,我发现了 CF 的一个非常奇怪的行为。当我配置Cache key 和 origin requests时,CF 总是给出不需要的输出。以下是我刚刚管理Cache 策略CachingDisabled的工作原理。

无缓存

但这有一个问题,因为没有任何标头传递给应用程序,因此我配置了Origin 请求策略并添加了AllViewer策略,因为我需要转发来自客户端的所有自定义标头/查询参数。

无缓存+转发用户参数

然而,当我收到 403 错误时,这会中断。

{
  "message": "Forbidden"
}
Run Code Online (Sandbox Code Playgroud)

我还尝试过将标头设置为 的旧版缓存设置All,但此选项也给出 403。我怀疑这与 CloudFront 附加的一些标头有关,这些标头在 API 网关处被拒绝,但我无法配置。

是什么赋予了?

amazon-web-services amazon-cloudfront amazon-route53 aws-api-gateway

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

Spring nullable注释生成未知的枚举常量警告

在我的应用中,每当我将@Nullable(从中导入org.springframework.lang.Nullable)到任何字段时,都会收到生成警告:

警告:java:未知的枚举常量javax.annotation.meta.When.MAYBE原因:javax.annotation.meta的类文件。

@NonNull以及Spring产生的其他空安全注释不会发出任何警告,因为它的实现并不重要import javax.annotation.meta.When

该应用程序运行正常,但警告很烦人。我正在使用Spring Boot 2.1.0和Java版本1.8.0_191

spring spring-boot

8
推荐指数
2
解决办法
3595
查看次数

如何在 IntelliJ 上使用 @ConfigurationProperties 配置 Spring Boot 配置注释处理器?

警告

在 IntelliJ 上,我得到了一个Spring Boot 配置注释处理器,该处理器未配置为具有 @ConfigurationProperties。下面是我的课:

@Configuration
@ConfigurationProperties(prefix = "abc")
@Data
@RefreshScope
class Config {
    String propA;
    String propB;
    ...
}
Run Code Online (Sandbox Code Playgroud)

我不确定是什么原因造成的,当我单击扳手进行设置时,我没有看到任何用于配置元数据文件的选项。

spring intellij-idea annotation-processing spring-boot

8
推荐指数
2
解决办法
6564
查看次数

Junit 5 - 如何为@CsvSource 传递多个空值?

我正在将测试方法从单个参数修改为多个:

@ParameterizedTest
@NullSource
@ValueSource({"foo", "bar"..})
void shouldReturnFalse(String x) {
  assertThat(someMethod(x)).isFalse();
}

@ParameterizedTest
@CsvSource({
  "null, null",
  "foo, bar"
})
void shouldReturnFalse(String x, String y) {
  assertThat(someMethod(x, y)).isFalse();
}
Run Code Online (Sandbox Code Playgroud)

null这里作为字符串文字而不是空文字传入。结果,此测试失败。此测试以前使用单个参数 with @NullSource,但在切换到多个参数时会出现以下错误:

org.junit.jupiter.api.extension.ParameterResolutionException:没有为参数注册 ParameterResolver...

我找不到解决这个问题的方法,我看到的解决方案相当笨拙和繁琐。有没有更简单的方法来提供值null

junit junit5

7
推荐指数
2
解决办法
2631
查看次数

从 SpringFox 迁移到 SpringDoc 后出现“映射到‘/v3/api-docs’的处理程序方法不明确”

使用 Spring Boot 2.4.5 和 IntelliJ 2021.2。迁移后

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-boot-starter</artifactId>
    <version>3.0.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-ui</artifactId>
    <version>1.5.10</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

每次我访问http://localhost:8080/swagger-ui.html. 该页面说:

获取错误未定义/v3/api-docs

当我检查日志时:

java.lang.IllegalStateException:为“/v3/api-docs”映射的处理程序方法不明确:{public org.springframework.http.ResponseEntity springfox.documentation.oas.web.OpenApiControllerWebMvc.getDocumentation(java.lang.String,javax.servlet) .http.HttpServletRequest), public java.lang.String org.springdoc.webmvc.api.OpenApiWebMvcResource.openapiJson(javax.servlet.http.HttpServletRequest,java.lang.String) 抛出 com.fasterxml.jackson.core.JsonProcessingException} org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lookupHandlerMethod(AbstractHandlerMethodMapping.java:426)在org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:377)在org.springframework.web.servlet。 mvc.method.RequestMappingInfoHandlerMapping.getHandlerInternal(RequestMappingInfoHandlerMapping.java:125)在org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping.getHandlerInternal(RequestMappingInfoHandlerMapping.java:67)在org.springframework.web.servlet.handler.AbstractHandlerMapping。 getHandler(AbstractHandlerMapping.java:498) 在 org.springframework.web.servlet.DispatcherServlet.getHandler(DispatcherServlet.java:1257) 在 org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1039) 在 org.springframework .web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963) 在 org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) 在 org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java :898)

似乎有一个重复的处理程序方法,与 SpringFox 具有相同的路径,我如何从 SpringFox 中删除该方法(它不再存在于我的 pom 文件中)?

spring-boot springfox springdoc

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

Ktlint 不允许通配符导入?(使用 IntelliJ 自动导入功能)

我正在使用 ktlint maven 插件(第一次使用)运行 Kotlin 项目。但是每当我进行 Maven 构建时。我经常看到这样的失败

src/main/kotlin/com/myproject/model/User.kt:7:1: Wildcard import (cannot be auto-corrected)
Run Code Online (Sandbox Code Playgroud)

因为我使用 IntelliJ,所以我经常依赖自动导入,其中许多子包被分组到一个通配符 (*) 中。这是 ktline 用来强制执行良好进口做法的吗?

intellij-idea kotlin ktlint

5
推荐指数
3
解决办法
4247
查看次数

分支指令和分支与链接指令之间的主要区别是什么?臂?

根据我的阅读,带链接的分支用于执行子程序调用,并将注册的链接复制回PC.

assembly arm

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

AWS CDK应用程序如何“引用”已经创建的aws lambda函数(而不在堆栈中创建新函数)?

我已经创建了一个在我的 aws 环境中调用的 lambda 函数add,我正在尝试构建一个 cdk 应用程序,它将生成一个新的 API Gateway,然后调用add.

我正在关注https://cdkworkshop.com/20-typescript/30-hello-cdk/300-apigw.html上的教程,我注意到我在网上遇到的所有示例似乎都以与以下类似的形式编写代码:

   const hello = new lambda.Function(this, 'HelloHandler', {
      runtime: lambda.Runtime.NODEJS_10_X,    // execution environment
      code: lambda.Code.fromAsset('lambda'),  // code loaded from "lambda" directory
      handler: 'hello.handler'                // file is "hello", function is "handler"
    });
    const api = new apiGateWay.LambdaRestApi(this, 'api', {
      handler: hello
    })
Run Code Online (Sandbox Code Playgroud)

上面的例子直接创建了一个新的 lambda 函数名HelloHanlder。我想引用我之前创建的 function add,而不是向堆栈中添加任何新的 lambda 函数,大致如下:

    const api = new apiGateWay.LambdaRestApi(this, 'api', {
      handler: "add"
    })
Run Code Online (Sandbox Code Playgroud)

这可以修复吗?

amazon-web-services aws-lambda aws-api-gateway aws-cdk

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

Spring WebClient如何在INFO级别记录每次重试?

我有以下 WebClient - 对 localhost:8090 进行 http 调用 - 定义了 bean:

@Configuration
class WebClientConfig {
    @Bean
    public WebClient webClientBean() {
        return WebClient.create("http://localhost:8090");
    }
}
Run Code Online (Sandbox Code Playgroud)

并调用另一个服务(8090):

Response response = requestBodySpec
        .retrieve()
        .bodyToMono(Response.class)
        .timeout(Duration.ofSeconds(5))
        .retry(2L)
        .doOnSuccess(res -> log.info(res))
        .doOnError(err -> log.error(err))
        .block();
Run Code Online (Sandbox Code Playgroud)

超时后我看到错误:

java.util.concurrent.TimeoutException:在“flatMap”中 5000 毫秒内没有观察到任何项目或终端信号

但我没有看到我指定的另外 2 次重试的日志;它们仅在我打开 TRACE 时可见:

跟踪 2120 --- [nio-8080-exec-1] oswrfclient.ExchangeFunctions : [9c7e1e0] HTTP POST http://localhost:8090/test, headers={masked}

有什么方法可以在重试发生时记录事件吗?与上面的日志类似,除了我必须 INFO 记录它。

spring spring-boot spring-webflux spring-webclient

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

AssertJ 无法在没有规模的情况下断言 BigDecimal 相等

我正在运行这样的断言:

assertThat(obj.getTotal()).isEqualTo(BigDecimal.valueOf(4))
Run Code Online (Sandbox Code Playgroud)

我正进入(状态

期望:<4.00> 等于:<4>

所以我试过了

assertThat(obj.getTotal()).isEqualTo(BigDecimal.valueOf(4.00))
Run Code Online (Sandbox Code Playgroud)

期望:<4.00> 等于:<4.0>

我找到了一种解决方法,在该方法中我将预期值的比例设置44.00,但我必须为测试中的所有 BigDecimal 变量这样做似乎很令人恼火。AssertJ 有没有我不知道的更好的方法?

java junit assertj

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

Spring Security @WithMockUser 似乎不适用于状态更改动词(发布,放置..)

这是我的设置:

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
        .authorizeRequests()
            .antMatchers("/signup", "/health").permitAll()
            .anyRequest().authenticated().and()
        .formLogin()
            .loginPage("/login")
            .permitAll()
...

Run Code Online (Sandbox Code Playgroud)

测试类:

@ExtendWith(SpringExtension.class)
@WebMvcTest
@WithMockUser
class ApiControllerTest {
    ...
Run Code Online (Sandbox Code Playgroud)

@WithMockUser 使用以下 GET 可以正常工作:

mockMvc.perform(get("/api/book/{id}", id))
        .andExpect(status().isOk())
...
Run Code Online (Sandbox Code Playgroud)

但不是 POST:

mockMvc.perform(post("/api/book")
        .contentType(MediaType.APPLICATION_JSON)
        .content(payload))
        .andExpect(status().isCreated())
...
Run Code Online (Sandbox Code Playgroud)

当我查看 MockHttpServletResponse 的日志时,我注意到响应重定向到登录页面,如下所示:

MockHttpServletResponse:
           Status = 302
    Error message = null
          Headers = [X-Content-Type-Options:"nosniff", X-XSS-Protection:"1; mode=block", Cache-Control:"no-cache, no-store, max-age=0, must-revalidate", Pragma:"no-cache", Expires:"0", X-Frame-Options:"DENY", Location:"/login"]
     Content type = null
             Body = 
    Forwarded URL = null
   Redirected URL = /login
          Cookies …
Run Code Online (Sandbox Code Playgroud)

spring-mvc spring-security spring-boot

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

程序已停止工作?如何使int数组大小超过1,000,000?

赋值:在eratosthenes筛上编写一个c ++程序,打印出1到1,000,000之间的所有素数.我已经意识到,当我有一个非常大的数字,如1,000,000,程序停止工作,对于9,000这样的小数字,该程序工作得非常好.有没有办法让1,000,000作为整数数组大小?

#include <iostream>

using namespace std;

void sieve(int [], int num);

int main()
{
    int numOfElements;
    cout<<"please input number"<<endl;
    cin>>numOfElements;
    int primeArray[numOfElements];
    sieve(primeArray, numOfElements);
    return 0;
}

//prime number: any whole number greater than one and has factors of only the number itself and one.
void sieve(int prime[], int num){
    int i,j;
    for(int a=0;a<num;a++){
        prime[a]=a+1;
    }
    prime[0]=0;//we know 1 is not a prime;
    for(i=2;i<=num;i++){
        if(prime[i-1]!=0){
            cout<<i<<endl;
        }
        for(j=i*i;j<=num;j+=i){
            prime[j-1]=0;
        }
    }

}
Run Code Online (Sandbox Code Playgroud)

c++ sieve-of-eratosthenes

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