]> juplo.de Git - website/blob
bafa43fd84935112ba1d2fb05b155d841a6ca2fe
[website] /
1 ---
2 _edit_last: "2"
3 _oembed_0a2776cf844d7b8b543bf000729407fe: '{{unknown}}'
4 _oembed_8a143b8145082a48cc586f0fdb19f9b5: '{{unknown}}'
5 _oembed_4484ca19961800dfe51ad98d0b1fcfef: '{{unknown}}'
6 _oembed_b0575eccf8471857f8e25e8d0f179f68: '{{unknown}}'
7 author: kai
8 categories:
9   - explained
10   - java
11   - spring-boot
12 classic-editor-remember: classic-editor
13 date: "2020-07-02T13:24:07+00:00"
14 guid: http://juplo.de/?p=970
15 parent_post_id: null
16 post_id: "970"
17 title: Actuator HTTP Trace Does Not Work With Spring Boot 2.2.x
18 url: /actuator-httptrace-does-not-work-with-spring-boot-2-2/
19
20 ---
21 ## TL;DR
22
23 In Spring Boot 2.2.x, you have to instanciate a **`@Bean`** of type **`InMemoryHttpTraceRepository`** to enable the HTTP Trace Actuator.
24
25 Jump to the [explanation](#explanation) of and [example code for the fix](#fix)
26
27 ## `Enabling HTTP Trace — Before 2.2.x...`
28
29 Spring Boot comes with a very handy feature called [Actuator](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#production-ready "Show the Spring Boot Documentation for the Actuator Feature").
30 Actuator provides a build-in production-ready REST-API, that can be used to monitor / menage / debug your bootified App.
31 To enable it — _prior to 2.2.x_ —, one only had to:
32
33 1. Specifiy the dependency for Spring Boot Actuator:
34
35    ```
36    <dependency>
37      <groupId>org.springframework.boot
38      <artifactId>spring-boot-starter-actuator
39    </dependency>
40
41    ```
42
43 1. Expose the needed endpoints via HTTP:
44
45    ```properties
46    management.endpoints.web.exposure.include=*
47
48    ```
49
50    - This exposes **all available endpoints** via HTTP.
51    - _**Advise:** Do not copy this into a production config_  
52
53       (Without thinking about it twice and — at least — [enable some security measures](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#production-ready-endpoints-security "Read, how to secure HTTP-endpoints in the documentation of Spring Boot") to protect the exposed endpoints!)
54
55 ## The problem: _It simply does not work any more in 2.2 :(_
56
57 _But..._
58
59 - If you upgrade your existing app with a working `httptrace`-actuator to Spring Boot 2.2.x, or
60 - If you start with a fresh app in Spring Boot 2.2.x and try to enable the `httptrace`-actuator [as described in the documentation](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#production-ready-endpoints-exposing-endpoints "Read, how to expose HTTP-endpoints in the documentation of Spring Boot")
61
62 **...it simply does not work at all!**
63
64 ## The Fix
65
66 The simple fix for this problem is, to add a `@Bean` of type `InMemoryHttpTraceRepository` to your **`@Configuration`**-class:
67
68 ```
69 @Bean
70 public HttpTraceRepository htttpTraceRepository()
71 {
72   return new InMemoryHttpTraceRepository();
73 }
74
75 ```
76
77 ## The Explanation
78
79 The cause of this problem is not a bug, but a legitimate change in the default configuration.
80 Unfortunately, this change is not noted in the according section of the documentation.
81 Instead it is burried in the [Upgrade Notes for Spring Boot 2.2](https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.2.0-M3-Release-Notes#actuator-http-trace-and-auditing-are-disabled-by-default)
82
83 The default-implementation stores the captured data in memory.
84 Hence, it consumes much memory, without the user knowing, or even worse: needing it.
85 This is especially undesirable in cluster environments, where memory is a precious good.
86 _And remember:_ Spring Boot was invented to simplify cluster deployments!
87
88 **That is, why this feature is now turned of by default and has to be turned on by the user explicitly, if needed.**