Skip to content

Commit 1ae93a4

Browse files
erikpetzoldjonashackt
authored andcommitted
do not invoke Bean methods in PostConstruct to prevent circular reference
spring-projects/spring-framework#27876
1 parent 5bb12b3 commit 1ae93a4

File tree

3 files changed

+13
-22
lines changed

3 files changed

+13
-22
lines changed

cxf-spring-boot-starter/src/main/java/de/codecentric/cxf/configuration/CxfAutoConfiguration.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,14 @@ public class CxfAutoConfiguration {
5353
@Value("${cxf.servicelist.title:CXF SpringBoot Starter - service list}")
5454
private String serviceListTitle;
5555

56-
private String serviceUrlEnding = "";
56+
private String serviceUrlEnding = null;
5757
private Object seiImplementation;
58-
private Service webServiceClient;
59-
6058

6159
@Bean
6260
public WebServiceAutoDetector webServiceAutoDetector(ApplicationContext applicationContext) throws BootStarterCxfException {
6361
return new WebServiceAutoDetector(new WebServiceScanner(), applicationContext);
6462
}
6563

66-
@PostConstruct
67-
public void setUp() throws BootStarterCxfException {
68-
webServiceClient = webServiceAutoDetector(null).searchAndInstantiateWebServiceClient();
69-
serviceUrlEnding = "/" + webServiceClient().getServiceName().getLocalPart();
70-
}
71-
7264
/**
7365
* We mostly want to autoinitialize the Endpoint and the CXFServlet.
7466
* But when in client mode, this isn´t always wanted (e.g. when you are in Client
@@ -126,7 +118,7 @@ public Endpoint endpoint() throws BootStarterCxfException {
126118
endpoint.setServiceName(webServiceClient().getServiceName());
127119
endpoint.setWsdlLocation(webServiceClient().getWSDLDocumentLocation().toString());
128120
if (publishedEndpointUrl.equals("NOT_SET")) {
129-
endpoint.setPublishedEndpointUrl(webServiceClient.getServiceName().getLocalPart());
121+
endpoint.setPublishedEndpointUrl(webServiceClient().getServiceName().getLocalPart());
130122
} else {
131123
endpoint.setPublishedEndpointUrl(publishedEndpointUrl);
132124
}
@@ -138,7 +130,7 @@ public Endpoint endpoint() throws BootStarterCxfException {
138130
@Bean
139131
public Service webServiceClient() throws BootStarterCxfException {
140132
// Needed for correct ServiceName & WSDLLocation to publish contract first incl. original WSDL
141-
return webServiceClient;
133+
return webServiceAutoDetector(null).searchAndInstantiateWebServiceClient();
142134
}
143135

144136
/**
@@ -152,7 +144,10 @@ public String baseUrl() {
152144
* @return the concrete Service URL-ending, where the WebService is configured according to your WSDL´s Service Name
153145
* (e.g. "/Weather" when there is this inside your WSDL: <wsdl:service name="Weather">)
154146
*/
155-
public String serviceUrlEnding() {
147+
public String serviceUrlEnding() throws BootStarterCxfException {
148+
if (serviceUrlEnding == null) {
149+
serviceUrlEnding = "/" + webServiceClient().getServiceName().getLocalPart();
150+
}
156151
return serviceUrlEnding;
157152
}
158153

@@ -161,7 +156,7 @@ public String serviceUrlEnding() {
161156
* the concrete Service URL-ending, where the WebService is configured according to your WSDL´s Service Name
162157
* (e.g. "/Weather" when there is this inside your WSDL: <wsdl:service name="Weather">)
163158
*/
164-
public String baseAndServiceEndingUrl() {
159+
public String baseAndServiceEndingUrl() throws BootStarterCxfException {
165160
return baseUrl() + serviceUrlEnding();
166161
}
167162

cxf-spring-boot-starter/src/main/java/de/codecentric/cxf/configuration/XmlValidationConfiguration.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,7 @@ public class XmlValidationConfiguration {
3030

3131
@Autowired
3232
public Endpoint endpoint;
33-
34-
@PostConstruct
35-
public void configureInterceptor2Endpoint() {
36-
EndpointImpl endpointImpl = (EndpointImpl)endpoint; // we need the implementation here, to configure our Interceptor
37-
endpointImpl.getOutFaultInterceptors().add(soapInterceptor());
38-
}
39-
33+
4034
@Bean
4135
public SoapFaultBuilder soapFaultBuilder() {
4236
return new SoapFaultBuilder();
@@ -46,6 +40,8 @@ public SoapFaultBuilder soapFaultBuilder() {
4640
public AbstractSoapInterceptor soapInterceptor() {
4741
XmlValidationInterceptor xmlValidationInterceptor = new XmlValidationInterceptor();
4842
xmlValidationInterceptor.setSoapFaultBuilder(soapFaultBuilder());
43+
EndpointImpl endpointImpl = (EndpointImpl)endpoint; // we need the implementation here, to configure our Interceptor
44+
endpointImpl.getOutFaultInterceptors().add(xmlValidationInterceptor);
4945
return xmlValidationInterceptor;
5046
}
5147
}

cxf-spring-boot-starter/src/test/java/de/codecentric/cxf/TestServiceSystemTestConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class TestServiceSystemTestConfiguration {
1818
* CXF JaxWs Client
1919
*/
2020
@Bean
21-
public WeatherService weatherServiceClient() {
21+
public WeatherService weatherServiceClient() throws BootStarterCxfException {
2222
JaxWsProxyFactoryBean jaxWsFactory = new JaxWsProxyFactoryBean();
2323
jaxWsFactory.setServiceClass(WeatherService.class);
2424
jaxWsFactory.setAddress(buildUrl());
@@ -31,7 +31,7 @@ public SoapRawClient soapRawClient() throws BootStarterCxfException {
3131
return new SoapRawClient(buildUrl(), WeatherService.class);
3232
}
3333

34-
private String buildUrl() {
34+
private String buildUrl() throws BootStarterCxfException {
3535
// return something like http://localhost:8084/soap-api/WeatherSoapService
3636
return "http://localhost:8087" + cxfAutoConfiguration.baseAndServiceEndingUrl();
3737
}

0 commit comments

Comments
 (0)