标签: spring-boot-actuator

Spring AOP 中获取请求/响应正文和标头

我想在我的方面之前和之后获取请求/响应正文和标头(如果可用)或如何获取它们。

我的意思是我认为前面的注释应该适用于请求,

注释后应适用于响应。可 ?

到目前为止我已经尝试过:

我尝试了日志库,这对我来说非常复杂,我不知道如何使用它。所以我放弃了。

执行器可以做一些技巧,但我正在做额外的工作,比如端点调用多少次等,因此我不能使用执行器。

另外,我尝试获取至少如下所示的请求标头,但我认为该标头始终相同。我无法像 httpservetrequest 那样获得 httpservletresponse 。

HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
                .getRequest();
Run Code Online (Sandbox Code Playgroud)

那么 request.getHeader("date")requestbody 呢?

如何获取请求体?响应主体?响应头?

我的方面文件:

@Aspect
@Component
public class AppAspect implements ResponseInfo{

    @Before("execution(@(@org.springframework.web.bind.annotation.RequestMapping *) * *(..))")
    public void loggingStartPointRequests(JoinPoint joinPoint) {

HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
                .getRequest();

}

@After("execution(@(@org.springframework.web.bind.annotation.RequestMapping *) * *(..))")
    public void loggingEndPointRequests(JoinPoint joinPoint) throws IOException {

    }

}
Run Code Online (Sandbox Code Playgroud)

我的控制器类:

@RestController
public class MainController {

    @GetMapping("/people") // 
    public ResponseEntity<Poeple> getAllPeople(@RequestParam(name = "page", required = false) Integer page,
            @RequestParam(name = …
Run Code Online (Sandbox Code Playgroud)

aop spring http spring-aop spring-boot-actuator

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

添加 Spring 执行器依赖项后无法构建项目

我已将 Spring 执行器依赖项添加到我的 Spring Boot 项目中,现在我无法执行 amvn clean install -Dspring.profiles.active=dev来构建项目,而是得到以下错误作为输出:

2020-07-03 12:44:23.454  WARN 34088 --- [           main] o.s.w.c.s.GenericWebApplicationContext   : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'healthIndicatorRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/LegacyHealthEndpointCompatibilityConfiguration.class]: Unsatisfied dependency expressed through method 'healthIndicatorRegistry' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthContributorRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate …
Run Code Online (Sandbox Code Playgroud)

java spring spring-boot spring-boot-actuator

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

Spring Boot 2 Actuator 端点在 GET 请求时返回 405

我正在配置 spring Boot 执行器,但 /actuator 和 /health 端点在每个 GET 请求中返回 405。

我打开了整个安全机制,但它不起作用:

management.endpoints.jmx.exposure.exclude=*
management.endpoints.web.exposure.include=health,info,beans,env
management.endpoint.health.enabled=true
management.security.enabled=false
management.endpoint.beans.cache.time-to-live=10s
management.endpoints.web.cors.allowed-origins=*
management.endpoints.web.cors.allowed-methods=GET,POST
Run Code Online (Sandbox Code Playgroud)

我添加了以下配置

@Configuration(proxyBeanMethods = false)
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Override
public void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests().antMatchers("/health", "/actuator").permitAll().and().csrf().disable();
    super.configure(http);
}
Run Code Online (Sandbox Code Playgroud)

}

因此,我按照教程进行操作,看起来非常简单,我不明白为什么在默认 GET 请求上收到此 405。当我使用 cURL 调用端点时:

 curl http://localhost:8080/sm-integration/health -v --> 405
 curl -X POST http://localhost:8080/sm-integration/health -v --> 400
Run Code Online (Sandbox Code Playgroud)

我不明白在执行 POST 时出现 400 Bad Request。文档指出 /health 是最基本和开放的端点,应该作为 GET 调用来调用。那么为什么是405呢?

更新 收到几个答案后,我设置了如下配置:

@Override
public void configure(HttpSecurity http) throws Exception …
Run Code Online (Sandbox Code Playgroud)

java spring spring-security spring-boot spring-boot-actuator

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

弹簧执行器更换主机

我正在尝试使用 Spring Boot 管理服务器设置 Spring Actuator。在我的本地机器上工作正常,但在 openshift 云中我遇到了一些问题......

当地的

d.c.b.a.c.r.ApplicationRegistrator       : Application registered itself as {id=93a4432e, name=orbe, managementUrl=http://localhost:8080/orbe, healthUrl=http://localhost:8080/orbe/status, serviceUrl=http://localhost:8080/orbe, statusInfo={}}}, source=http-api, metadata={}, info={}}
Run Code Online (Sandbox Code Playgroud)

d.c.b.a.c.r.ApplicationRegistrator       : Application registered itself as {id=7068c1d1, name=orbe, managementUrl=http://orbe-api-334-ciunv:8080/orbe, healthUrl=http://orbe-api-334-ciunv:8080/orbe/status, serviceUrl=http://orbe-api-334-ciunv:8080/orbe, statusInfo={status=UNKNOWN, timestamp=1496071160897, details={}}, source=http-api, metadata={}, info={}}
Run Code Online (Sandbox Code Playgroud)

在本地,应用程序具有正确的主机 (localhost),但在云中 Openshift (Kubernetes) 主机名是 POD 名称容器,并且无法正常工作(Spring Boot Admin 未检测到该应用程序,并且运行状况检查返回 UNKNOWN。

请问有人可以帮助我吗?谢谢!

spring openshift spring-boot kubernetes spring-boot-actuator

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

如何获取Spring Boot默认的Kafka消费者对象

我对 Kafka 消费者的配置位于 application.yaml 文件中。我知道如果我只有 1 个消费者,我不需要创建 ConsumerFactory bean,它会默认由 spring 设置。我需要测试我的消费者,因此我需要访问测试文件中的消费者对象,并且我不想再次配置它(我想使用 application.yaml 中的默认配置)文件来创建消费者对象。这怎么可能?

java spring-boot-actuator spring-kafka spring-boot-test

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