To add a bit more context and explanation....
I am using AnnotationConfigWebApplicationContext.
so web.xml includes
Code:
<context-param>
<param-name>contextClass</param-name>
<param-value>
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>uk.co.my.test.wiring.ApplicationWiring</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
and the ApplicationWiring class looks like..
Code:
@Configuration
public class ApplicationWiring {
@Bean
public VehicleDetailsService vehicleDetailsService(){
if (ApplicationConfiguration.stubMode) {
return new StubVehicleDetailsService(liveStubDataHolder());
} else {
return new LiveVehicleDetailsService(applicationConfiguration(), vehicleDetailsFactory());
}
}
@Bean
public VehicleDetailsFactory vehicleDetailsFactory() {
return new VehicleDetailsFactory(applicationConfiguration());
}
@Bean
public ApplicationConfiguration applicationConfiguration() {
return new ApplicationConfiguration(new Properties());
}
@Bean
public LiveStubDataHolder liveStubDataHolder() {
return new LiveStubDataHolder();
}
}
I am running the app from embedded jetty - so I've got a starter class for 'real' services and one for 'stub'
This is the stub mode...
Code:
public class EmbeddedDefaultApplicationStarterWithStubs {
public static void main(String... args) throws Exception {
ApplicationConfiguration.stubMode = true;
new EmbeddedUnpackedWarContainer("src/main/webapp").start();
}
}
It kind of works....
But what I'd really like to do is switch in a different ApplicationWiring depending on whether stubsMode is true or not, without having to edit web.xml
Is there a better way of doing this? Any suggestions most welcome...