Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cache auto configuration #1484

Merged
merged 1 commit into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions riptide-spring-boot-autoconfigure/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ Required when `caching` is enabled.

```xml
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient-cache</artifactId>
<version>${httpclient.version}</version>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5-cache</artifactId>
<version>${httpclient5.version}</version>
</dependency>
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.apache.hc.client5.http.impl.cache.CacheConfig;
import org.apache.hc.core5.util.TimeValue;
import org.apiguardian.api.API;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.stereotype.Component;
import org.zalando.riptide.UrlResolution;
import org.zalando.riptide.autoconfigure.RiptideProperties.Caching.Heuristic;
import org.zalando.riptide.autoconfigure.RiptideProperties.CertificatePinning.Keystore;
Expand Down Expand Up @@ -35,6 +36,7 @@
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Component
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting that you need to add this annotation as @ConfigurationProperties should normally make this available to Spring.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intellij showed an error saying not registered via @enableconfigurationproperties or marked as spring component.

The project compiled anyway, but I followed the advice here:
https://stackoverflow.com/a/57950415/459391

This is expected as @ConfigurationProperties does not make a class a Spring Component. Mark the class with @component and it should work. Note that a class can only be injected if it is a Component.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the insights. Yes, I remember that you have to add this annotation to your main class for example, to get this working. I guess, given that this is a library, it makes sense to follow that approach.

@ConfigurationProperties(prefix = "riptide")
public final class RiptideProperties {

Expand All @@ -46,6 +48,11 @@ public final class RiptideProperties {
@NoArgsConstructor
@AllArgsConstructor
public static final class Defaults {
// These constants where copied from org.apache.hc.client5.http.impl.cache.CacheConfig
private static final int DEFAULT_MAX_OBJECT_SIZE_BYTES = 8192;
private static final int DEFAULT_MAX_CACHE_ENTRIES = 1000;
private static final float DEFAULT_HEURISTIC_COEFFICIENT = 0.1F;
private static final TimeValue DEFAULT_HEURISTIC_LIFETIME = TimeValue.ZERO_MILLISECONDS;

private UrlResolution urlResolution = UrlResolution.RFC;

Expand Down Expand Up @@ -112,12 +119,12 @@ public static final class Defaults {
false,
false,
null,
CacheConfig.DEFAULT_MAX_OBJECT_SIZE_BYTES,
CacheConfig.DEFAULT_MAX_CACHE_ENTRIES,
DEFAULT_MAX_OBJECT_SIZE_BYTES,
DEFAULT_MAX_CACHE_ENTRIES,
new Heuristic(
false,
CacheConfig.DEFAULT_HEURISTIC_COEFFICIENT,
TimeSpan.of(CacheConfig.DEFAULT_HEURISTIC_LIFETIME.toSeconds(), SECONDS)
DEFAULT_HEURISTIC_COEFFICIENT,
TimeSpan.of(DEFAULT_HEURISTIC_LIFETIME.toSeconds(), SECONDS)
)
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
org.zalando.riptide.autoconfigure.OpenTracingFlowIdAutoConfiguration
org.zalando.riptide.autoconfigure.RiptideAutoConfiguration
org.zalando.riptide.autoconfigure.RiptideTestAutoConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.zalando.riptide.autoconfigure.RiptideTestAutoConfiguration