Skip to content

Commit ccd34c6

Browse files
committed
refactor: configure SpringBus without PostConstruct
reason: sping-boot prep. spring-boot complains because of cyclic dependency. the config class creates a SpringBus bean, but also needs it to configure services via calling springBus()
1 parent d457f56 commit ccd34c6

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/main/java/de/rwth/idsg/steve/config/OcppConfiguration.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.springframework.context.annotation.Bean;
3535
import org.springframework.context.annotation.Configuration;
3636

37-
import jakarta.annotation.PostConstruct;
3837
import java.util.Collection;
3938
import java.util.Collections;
4039
import java.util.List;
@@ -62,32 +61,33 @@ public class OcppConfiguration {
6261
private final ocpp.cs._2015._10.CentralSystemService ocpp16Server;
6362
private final MessageHeaderInterceptor messageHeaderInterceptor;
6463

65-
@PostConstruct
66-
public void init() {
64+
@Bean(name = Bus.DEFAULT_BUS_ID, destroyMethod = "shutdown")
65+
public SpringBus cxf() {
66+
SpringBus bus = new SpringBus();
67+
configure(bus);
68+
return bus;
69+
}
70+
71+
private void configure(Bus bus) {
6772
List<Interceptor<? extends Message>> interceptors = asList(new MessageIdInterceptor(), messageHeaderInterceptor);
6873
List<Feature> logging = singletonList(LoggingFeatureProxy.INSTANCE.get());
6974

70-
createOcppService(ocpp12Server, "/CentralSystemServiceOCPP12", interceptors, logging);
71-
createOcppService(ocpp15Server, "/CentralSystemServiceOCPP15", interceptors, logging);
72-
createOcppService(ocpp16Server, "/CentralSystemServiceOCPP16", interceptors, logging);
75+
createOcppService(bus, ocpp12Server, "/CentralSystemServiceOCPP12", interceptors, logging);
76+
createOcppService(bus, ocpp15Server, "/CentralSystemServiceOCPP15", interceptors, logging);
77+
createOcppService(bus, ocpp16Server, "/CentralSystemServiceOCPP16", interceptors, logging);
7378

7479
// Just a dummy service to route incoming messages to the appropriate service version. This should be the last
7580
// one to be created, since in MediatorInInterceptor we go over created/registered services and build a map.
7681
//
77-
List<Interceptor<? extends Message>> mediator = singletonList(new MediatorInInterceptor(springBus()));
78-
createOcppService(ocpp12Server, CONFIG.getRouterEndpointPath(), mediator, Collections.emptyList());
79-
}
80-
81-
@Bean(name = Bus.DEFAULT_BUS_ID, destroyMethod = "shutdown")
82-
public SpringBus springBus() {
83-
return new SpringBus();
82+
List<Interceptor<? extends Message>> mediator = singletonList(new MediatorInInterceptor(bus));
83+
createOcppService(bus, ocpp12Server, CONFIG.getRouterEndpointPath(), mediator, Collections.emptyList());
8484
}
8585

86-
private void createOcppService(Object serviceBean, String address,
86+
private void createOcppService(Bus bus, Object serviceBean, String address,
8787
List<Interceptor<? extends Message>> interceptors,
8888
Collection<? extends Feature> features) {
8989
JaxWsServerFactoryBean f = new JaxWsServerFactoryBean();
90-
f.setBus(springBus());
90+
f.setBus(bus);
9191
f.setServiceBean(serviceBean);
9292
f.setAddress(address);
9393
f.getFeatures().addAll(features);

0 commit comments

Comments
 (0)