我正在尝试使用自定义源名称设置 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
在我的应用中,每当我将@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
在 IntelliJ 上,我得到了一个Spring Boot 配置注释处理器,该处理器未配置为具有 @ConfigurationProperties。下面是我的课:
@Configuration
@ConfigurationProperties(prefix = "abc")
@Data
@RefreshScope
class Config {
String propA;
String propB;
...
}
Run Code Online (Sandbox Code Playgroud)
我不确定是什么原因造成的,当我单击扳手进行设置时,我没有看到任何用于配置元数据文件的选项。
我正在将测试方法从单个参数修改为多个:
@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
?
使用 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 文件中)?
我正在使用 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 用来强制执行良好进口做法的吗?
我已经创建了一个在我的 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)
这可以修复吗?
我有以下 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 记录它。
我正在运行这样的断言:
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>
我找到了一种解决方法,在该方法中我将预期值的比例设置4
为4.00
,但我必须为测试中的所有 BigDecimal 变量这样做似乎很令人恼火。AssertJ 有没有我不知道的更好的方法?
这是我的设置:
@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) 赋值:在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)