Skip to content

Commit f17a0b3

Browse files
authored
spring-cloudGH-369: Fix HeaderEnricher for no proxyBeanMethod (spring-cloud#376)
Spring Boot `@AutoConfiguration` comes now with a `proxyBeanMethods = false`, so we cannot call bean methods within the same configuration class. * Rework `HeaderEnricherFunctionConfiguration` for bean methods autowiring * Create an `ExpressionEvaluatingHeaderValueMessageProcessor` instances directly in the `headerEnricher` bean definition and propagate an injected `BeanFactory` * Re-enable disabled tests Fixes spring-cloud#369
1 parent 1b199b8 commit f17a0b3

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
lines changed

Diff for: applications/processor/header-enricher-processor/src/test/java/org/springframework/cloud/stream/app/processor/header/enricher/HeaderEnricherProcessorTests.java

-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.springframework.cloud.stream.app.processor.header.enricher;
1818

1919
import org.hamcrest.MatcherAssert;
20-
import org.junit.jupiter.api.Disabled;
2120
import org.junit.jupiter.api.Test;
2221

2322
import org.springframework.boot.WebApplicationType;
@@ -40,7 +39,6 @@
4039
* @author Christian Tzolov
4140
* @author Soby Chacko
4241
*/
43-
@Disabled
4442
public class HeaderEnricherProcessorTests {
4543

4644
@Test

Diff for: functions/function/header-enricher-function/src/main/java/org/springframework/cloud/fn/header/enricher/HeaderEnricherFunctionConfiguration.java

+10-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2020 the original author or authors.
2+
* Copyright 2020-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,13 +22,12 @@
2222
import java.util.Properties;
2323
import java.util.function.Function;
2424

25+
import org.springframework.beans.factory.BeanFactory;
2526
import org.springframework.beans.factory.annotation.Autowired;
26-
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
2727
import org.springframework.boot.autoconfigure.AutoConfiguration;
2828
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
2929
import org.springframework.boot.context.properties.EnableConfigurationProperties;
3030
import org.springframework.context.annotation.Bean;
31-
import org.springframework.context.annotation.Scope;
3231
import org.springframework.integration.transformer.HeaderEnricher;
3332
import org.springframework.integration.transformer.support.ExpressionEvaluatingHeaderValueMessageProcessor;
3433
import org.springframework.messaging.Message;
@@ -37,6 +36,7 @@
3736
* @author Gary Russell
3837
* @author Christian Tzolov
3938
* @author Soby Chacko
39+
* @author Artem Bilan
4040
*/
4141
@AutoConfiguration
4242
@EnableConfigurationProperties(HeaderEnricherFunctionProperties.class)
@@ -47,28 +47,25 @@ public class HeaderEnricherFunctionConfiguration {
4747
private HeaderEnricherFunctionProperties properties;
4848

4949
@Bean
50-
public Function<Message<?>, Message<?>> headerEnricherFunction() {
51-
return headerEnricher()::transform;
50+
public Function<Message<?>, Message<?>> headerEnricherFunction(HeaderEnricher headerEnricher) {
51+
return headerEnricher::transform;
5252
}
5353

5454
@Bean
55-
public HeaderEnricher headerEnricher() {
55+
public HeaderEnricher headerEnricher(BeanFactory beanFactory) {
5656
Map<String, ExpressionEvaluatingHeaderValueMessageProcessor<?>> headersToAdd = new HashMap<>();
5757
Properties props = this.properties.getHeaders();
5858
Enumeration<?> enumeration = props.propertyNames();
5959
while (enumeration.hasMoreElements()) {
6060
String propertyName = (String) enumeration.nextElement();
61-
headersToAdd.put(propertyName, processor(props.getProperty(propertyName)));
61+
ExpressionEvaluatingHeaderValueMessageProcessor<?> headerValueMessageProcessor =
62+
new ExpressionEvaluatingHeaderValueMessageProcessor<>(props.getProperty(propertyName), null);
63+
headerValueMessageProcessor.setBeanFactory(beanFactory);
64+
headersToAdd.put(propertyName, headerValueMessageProcessor);
6265
}
6366
HeaderEnricher headerEnricher = new HeaderEnricher(headersToAdd);
6467
headerEnricher.setDefaultOverwrite(this.properties.isOverwrite());
6568
return headerEnricher;
6669
}
6770

68-
@Bean
69-
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) // Need a new processor for each header
70-
public ExpressionEvaluatingHeaderValueMessageProcessor<?> processor(String expression) {
71-
return new ExpressionEvaluatingHeaderValueMessageProcessor<>(expression, null);
72-
}
73-
7471
}

Diff for: functions/function/header-enricher-function/src/test/java/org/springframework/cloud/fn/header/enricher/HeaderEnricherFunctionApplicationTests.java

-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.util.function.Function;
2020

21-
import org.junit.jupiter.api.Disabled;
2221
import org.junit.jupiter.api.Test;
2322

2423
import org.springframework.beans.factory.annotation.Autowired;
@@ -42,7 +41,6 @@
4241
"header.enricher.headers=foo='bar' \\n baz='fiz' \\n buz=payload \\n jaz=@value",
4342
"header.enricher.overwrite = true" })
4443
@DirtiesContext
45-
@Disabled
4644
public class HeaderEnricherFunctionApplicationTests {
4745

4846
@Autowired

0 commit comments

Comments
 (0)