Fix problem with BeanPostProcessing (#1447)
Change endpoint mapping from BeanPostProcessor to SmartInitializingSingleton Added Test and updated test.sh to invoke with separate profile. Fixes #1435
This commit is contained in:
committed by
GitHub
parent
6d72c254e6
commit
fe43f881c1
@@ -9,3 +9,4 @@ MAVEN_OPTS="-Duser.name=spring-builds+jenkins -Duser.home=/tmp/jenkins-home" \
|
||||
MAVEN_OPTS="-Duser.name=spring-builds+jenkins -Duser.home=/tmp/jenkins-home" \
|
||||
./mvnw -s settings.xml \
|
||||
-P-default,${PROFILE},observation clean dependency:list test -Dsort -B -U
|
||||
|
||||
|
||||
@@ -248,6 +248,115 @@
|
||||
</dependencies>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>default</id>
|
||||
<activation>
|
||||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.13.0</version>
|
||||
<configuration>
|
||||
<testExcludes>
|
||||
<exclude>**/ObservationInWsConfigurerTests.*</exclude>
|
||||
</testExcludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.5.2</version>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>**/ObservationInWsConfigurerTests.*</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>observation</id>
|
||||
<properties>
|
||||
<spring-boot.version>3.2.12</spring-boot.version>
|
||||
</properties>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
<version>${spring-boot.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>micrometer-tracing-bridge-brave</artifactId>
|
||||
<version>1.3.4</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.13.0</version>
|
||||
<configuration>
|
||||
<testExcludes>
|
||||
<exclude>**/wsdl/**/*</exclude>
|
||||
</testExcludes>
|
||||
<testIncludes>
|
||||
<include>**/ObservationInWsConfigurerTests.*</include>
|
||||
</testIncludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.5.2</version>
|
||||
<configuration>
|
||||
<failIfNoTests>true</failIfNoTests>
|
||||
<systemProperties>
|
||||
<property>
|
||||
<name>spring-boot.run.profiles</name>
|
||||
<value>observation</value>
|
||||
</property>
|
||||
</systemProperties>
|
||||
<includes>
|
||||
<include>**/ObservationInWsConfigurerTests.java</include>
|
||||
</includes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>docs</id>
|
||||
|
||||
|
||||
@@ -21,9 +21,7 @@ import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.beans.factory.SmartInitializingSingleton;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.ws.server.endpoint.MethodEndpoint;
|
||||
@@ -54,11 +52,12 @@ import org.springframework.ws.soap.addressing.server.annotation.Address;
|
||||
* incoming message.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Corneil du Plessis (with thanks to Chris Bono)
|
||||
* @see Action
|
||||
* @see Address
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public class AnnotationActionEndpointMapping extends AbstractActionMethodEndpointMapping implements BeanPostProcessor {
|
||||
public class AnnotationActionEndpointMapping extends AbstractActionMethodEndpointMapping implements SmartInitializingSingleton {
|
||||
|
||||
/** Returns the 'endpoint' annotation type. Default is {@link Endpoint}. */
|
||||
protected Class<? extends Annotation> getEndpointAnnotationType() {
|
||||
@@ -133,16 +132,8 @@ public class AnnotationActionEndpointMapping extends AbstractActionMethodEndpoin
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
|
||||
return bean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||
if (AopUtils.getTargetClass(bean).getAnnotation(getEndpointAnnotationType()) != null) {
|
||||
registerMethods(bean);
|
||||
}
|
||||
return bean;
|
||||
public void afterSingletonsInstantiated() {
|
||||
this.getApplicationContext().getBeansWithAnnotation(this.getEndpointAnnotationType())
|
||||
.values().forEach(this::registerMethods);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package org.springframework.ws.observation;
|
||||
|
||||
import io.micrometer.observation.ObservationRegistry;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.slf4j.MDC;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.boot.test.web.server.LocalServerPort;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.ws.config.annotation.WsConfigurerAdapter;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* This test is executed by using observation Maven profile and explicitly excluding the default profile.
|
||||
* This test relies on dependencies that cause problems with other tests in Spring WS Core.
|
||||
* @author Corneil du Plessis
|
||||
*/
|
||||
@Profile("observation")
|
||||
@SpringBootTest(classes = ObservationInWsConfigurerTests.WsTracingApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class ObservationInWsConfigurerTests {
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
@Autowired
|
||||
private TestRestTemplate restTemplate;
|
||||
|
||||
@Test
|
||||
void responseShouldNotBeEmpty() {
|
||||
final ResponseEntity<String> response =
|
||||
restTemplate.getForEntity("http://localhost:" + port + "/test", String.class);
|
||||
assertThat(response.getBody()).isNotEmpty();
|
||||
}
|
||||
|
||||
@RestController
|
||||
public static class TestEndpoint {
|
||||
private static final Logger log = LoggerFactory.getLogger(TestEndpoint.class);
|
||||
|
||||
@GetMapping("/test")
|
||||
public String test() {
|
||||
log.info("test");
|
||||
return MDC.get("spanId");
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
public static class WsConfig extends WsConfigurerAdapter {
|
||||
private final ObservationRegistry observationRegistry;
|
||||
|
||||
public WsConfig(ObservationRegistry observationRegistry) {
|
||||
this.observationRegistry = observationRegistry;
|
||||
}
|
||||
}
|
||||
|
||||
@SpringBootApplication
|
||||
@Import(WsConfig.class)
|
||||
public static class WsTracingApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(WsTracingApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user