Skip to content

Commit 070d044

Browse files
author
Corneil du Plessis
authored
Fix problem with BeanPostProcessing (#1443)
* Fix problem with BeanPostProcessing Change endpoint mapping from BeanPostProcessor to SmartInitializingSingleton Added Test and updated test.sh to invoke with separate profile. Fixes #1435
1 parent e14e483 commit 070d044

File tree

4 files changed

+193
-15
lines changed

4 files changed

+193
-15
lines changed

ci/test.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ set -euo pipefail
55
MAVEN_OPTS="-Duser.name=spring-builds+jenkins -Duser.home=/tmp/jenkins-home" \
66
./mvnw -s settings.xml \
77
-P${PROFILE} clean dependency:list test -Dsort -B -U
8+
# Provides for testing org.springframework.ws.observation.ObservationInWsConfigurerTests separately
9+
MAVEN_OPTS="-Duser.name=spring-builds+jenkins -Duser.home=/tmp/jenkins-home" \
10+
./mvnw -s settings.xml \
11+
-P-default,observation clean dependency:list test -Dsort -B -U

spring-ws-core/pom.xml

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,115 @@
248248
</dependencies>
249249

250250
<profiles>
251+
<profile>
252+
<id>default</id>
253+
<activation>
254+
<activeByDefault>true</activeByDefault>
255+
</activation>
256+
<build>
257+
<plugins>
258+
<plugin>
259+
<groupId>org.apache.maven.plugins</groupId>
260+
<artifactId>maven-compiler-plugin</artifactId>
261+
<version>3.13.0</version>
262+
<configuration>
263+
<testExcludes>
264+
<exclude>**/ObservationInWsConfigurerTests.*</exclude>
265+
</testExcludes>
266+
</configuration>
267+
</plugin>
268+
<plugin>
269+
<groupId>org.apache.maven.plugins</groupId>
270+
<artifactId>maven-surefire-plugin</artifactId>
271+
<version>3.5.2</version>
272+
<configuration>
273+
<excludes>
274+
<exclude>**/ObservationInWsConfigurerTests.*</exclude>
275+
</excludes>
276+
</configuration>
277+
</plugin>
278+
</plugins>
279+
</build>
280+
</profile>
281+
<profile>
282+
<id>observation</id>
283+
<properties>
284+
<spring-boot.version>3.3.6</spring-boot.version>
285+
</properties>
286+
<dependencyManagement>
287+
<dependencies>
288+
<dependency>
289+
<groupId>org.springframework.boot</groupId>
290+
<artifactId>spring-boot-dependencies</artifactId>
291+
<type>pom</type>
292+
<scope>import</scope>
293+
<version>${spring-boot.version}</version>
294+
</dependency>
295+
</dependencies>
296+
</dependencyManagement>
297+
<dependencies>
298+
<dependency>
299+
<groupId>io.micrometer</groupId>
300+
<artifactId>micrometer-tracing-bridge-brave</artifactId>
301+
<version>1.3.4</version>
302+
<scope>test</scope>
303+
</dependency>
304+
<dependency>
305+
<groupId>org.springframework.boot</groupId>
306+
<artifactId>spring-boot-starter-web</artifactId>
307+
<scope>test</scope>
308+
</dependency>
309+
<dependency>
310+
<groupId>org.springframework.boot</groupId>
311+
<artifactId>spring-boot-starter-test</artifactId>
312+
<scope>test</scope>
313+
</dependency>
314+
<dependency>
315+
<groupId>org.springframework.boot</groupId>
316+
<artifactId>spring-boot-starter-actuator</artifactId>
317+
<scope>test</scope>
318+
</dependency>
319+
<dependency>
320+
<groupId>org.assertj</groupId>
321+
<artifactId>assertj-core</artifactId>
322+
<scope>test</scope>
323+
</dependency>
324+
</dependencies>
325+
<build>
326+
<plugins>
327+
<plugin>
328+
<groupId>org.apache.maven.plugins</groupId>
329+
<artifactId>maven-compiler-plugin</artifactId>
330+
<version>3.13.0</version>
331+
<configuration>
332+
<testExcludes>
333+
<exclude>**/wsdl/**/*</exclude>
334+
</testExcludes>
335+
<testIncludes>
336+
<include>**/ObservationInWsConfigurerTests.*</include>
337+
</testIncludes>
338+
</configuration>
339+
</plugin>
340+
<plugin>
341+
<groupId>org.apache.maven.plugins</groupId>
342+
<artifactId>maven-surefire-plugin</artifactId>
343+
<version>3.5.2</version>
344+
<configuration>
345+
<failIfNoTests>true</failIfNoTests>
346+
<systemProperties>
347+
<property>
348+
<name>spring-boot.run.profiles</name>
349+
<value>observation</value>
350+
</property>
351+
</systemProperties>
352+
<includes>
353+
<include>**/ObservationInWsConfigurerTests.java</include>
354+
</includes>
355+
</configuration>
356+
</plugin>
357+
</plugins>
358+
</build>
359+
</profile>
251360
<profile>
252361
<id>docs</id>
253362

spring-ws-core/src/main/java/org/springframework/ws/soap/addressing/server/AnnotationActionEndpointMapping.java

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
import java.net.URI;
2222
import java.net.URISyntaxException;
2323

24-
import org.springframework.aop.support.AopUtils;
25-
import org.springframework.beans.BeansException;
26-
import org.springframework.beans.factory.config.BeanPostProcessor;
24+
import org.springframework.beans.factory.SmartInitializingSingleton;
2725
import org.springframework.core.annotation.AnnotationUtils;
2826
import org.springframework.util.StringUtils;
2927
import org.springframework.ws.server.endpoint.MethodEndpoint;
@@ -54,11 +52,12 @@
5452
* incoming message.
5553
*
5654
* @author Arjen Poutsma
55+
* @author Corneil du Plessis (with thanks to Chris Bono)
5756
* @see Action
5857
* @see Address
5958
* @since 1.5.0
6059
*/
61-
public class AnnotationActionEndpointMapping extends AbstractActionMethodEndpointMapping implements BeanPostProcessor {
60+
public class AnnotationActionEndpointMapping extends AbstractActionMethodEndpointMapping implements SmartInitializingSingleton {
6261

6362
/** Returns the 'endpoint' annotation type. Default is {@link Endpoint}. */
6463
protected Class<? extends Annotation> getEndpointAnnotationType() {
@@ -133,16 +132,8 @@ private URI getActionUri(String action, MethodEndpoint methodEndpoint) {
133132
}
134133
}
135134

136-
@Override
137-
public final Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
138-
return bean;
139-
}
140-
141-
@Override
142-
public final Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
143-
if (AopUtils.getTargetClass(bean).getAnnotation(getEndpointAnnotationType()) != null) {
144-
registerMethods(bean);
145-
}
146-
return bean;
135+
public void afterSingletonsInstantiated() {
136+
this.getApplicationContext().getBeansWithAnnotation(this.getEndpointAnnotationType())
137+
.values().forEach(this::registerMethods);
147138
}
148139
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package org.springframework.ws.observation;
2+
3+
import io.micrometer.observation.ObservationRegistry;
4+
import org.junit.jupiter.api.Test;
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
import org.slf4j.MDC;
8+
9+
import org.springframework.beans.factory.annotation.Autowired;
10+
import org.springframework.boot.SpringApplication;
11+
import org.springframework.boot.autoconfigure.SpringBootApplication;
12+
import org.springframework.boot.test.context.SpringBootTest;
13+
import org.springframework.boot.test.web.client.TestRestTemplate;
14+
import org.springframework.boot.test.web.server.LocalServerPort;
15+
import org.springframework.context.annotation.Configuration;
16+
import org.springframework.context.annotation.Import;
17+
import org.springframework.context.annotation.Profile;
18+
import org.springframework.http.ResponseEntity;
19+
import org.springframework.web.bind.annotation.GetMapping;
20+
import org.springframework.web.bind.annotation.RestController;
21+
import org.springframework.ws.config.annotation.WsConfigurerAdapter;
22+
23+
import static org.assertj.core.api.Assertions.assertThat;
24+
25+
/**
26+
* This test is executed by using observation Maven profile and explicitly excluding the default profile.
27+
* This test relies on dependencies that cause problems with other tests in Spring WS Core.
28+
* @author Corneil du Plessis
29+
*/
30+
@Profile("observation")
31+
@SpringBootTest(classes = ObservationInWsConfigurerTests.WsTracingApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
32+
public class ObservationInWsConfigurerTests {
33+
@LocalServerPort
34+
private int port;
35+
36+
@Autowired
37+
private TestRestTemplate restTemplate;
38+
39+
@Test
40+
void responseShouldNotBeEmpty() {
41+
final ResponseEntity<String> response =
42+
restTemplate.getForEntity("http://localhost:" + port + "/test", String.class);
43+
assertThat(response.getBody()).isNotEmpty();
44+
}
45+
46+
@RestController
47+
public static class TestEndpoint {
48+
private static final Logger log = LoggerFactory.getLogger(TestEndpoint.class);
49+
50+
@GetMapping("/test")
51+
public String test() {
52+
log.info("test");
53+
return MDC.get("spanId");
54+
}
55+
}
56+
57+
@Configuration
58+
public static class WsConfig extends WsConfigurerAdapter {
59+
private final ObservationRegistry observationRegistry;
60+
61+
public WsConfig(ObservationRegistry observationRegistry) {
62+
this.observationRegistry = observationRegistry;
63+
}
64+
}
65+
66+
@SpringBootApplication
67+
@Import(WsConfig.class)
68+
public static class WsTracingApplication {
69+
public static void main(String[] args) {
70+
SpringApplication.run(WsTracingApplication.class, args);
71+
}
72+
73+
}
74+
}

0 commit comments

Comments
 (0)