Issue
I am a beginner in developing web services and I have a jaxrs web service which has the folllowing config :
@Configuration
@ComponentScan("com.example.service")
@ComponentScan("com.example.services")
@ImportResource({
"classpath:/META-INF/cxf/cxf.xml",
"classpath:/META-INF/cxf/cxf-servlet.xml"
})
public class AppConfig {
@Bean(destroyMethod = "shutdown")
public SpringBus cxf() {
return new SpringBus();
}
@Bean
public Server jaxRsServer() {
//Define swagger feature
Swagger2Feature feature = new Swagger2Feature();
//REST Factory with all services,providers and features
JAXRSServerFactoryBean factory = RuntimeDelegate.getInstance().createEndpoint(jaxRsApiApplication(), JAXRSServerFactoryBean.class);
factory.setServiceBeans(Arrays.asList(baseRestService(), materialsRestService(), batchRestService(), billingRestService(), locationRestService(), customerRestService(), equipmentRestService(), projectRestService(), reservationRestService(), waferRestService()));
factory.setAddress(factory.getAddress());
factory.setProviders(Arrays.asList(jsonProvider(), authenticationService()));
factory.getFeatures().add(feature);
return factory.create();
}
@Bean
public JaxRsApiApplication jaxRsApiApplication() {
return new JaxRsApiApplication();
}
@Bean
public JacksonJsonProvider jsonProvider() {
return new JacksonJsonProvider();
}
@Bean
public AuthenticationService authenticationService() {
return new AuthenticationService();
}
**all other beans**
Recently I started getting the following exception: java.lang.IllegalStateException: @Bean method AppConfig.materialsRestService called as a bean reference for type [com.phoenixbv.rs.MaterialsRestService] but overridden by non-compatible bean instance of type [com.sun.proxy.$Proxy159]. Overriding bean of same name declared in: com.example.config.AppConfig
I would appreciate any help !
Solution
I was able to solve the problem by creating Interfaces to the service classes and the injecting the interfaces into the factory.
Answered By - F. Zamfirov