我是开发Web服务的初学者,我有一个jaxrs web服务,它具有以下配置:
@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**
最近我开始收到以下异常: java.lang.IllegalStateException:@Bean方法AppConfig.materialsRestService被调用为类型[com.phoenixbv.rs.MaterialsRestService]的bean引用,但被[com.sun.proxy。$ Proxy159]类型的非兼容bean实例覆盖。覆盖在com.example.config.AppConfig
中声明的同名bean我将不胜感激任何帮助!
答案 0 :(得分:1)
我能够通过创建服务类的接口并将接口注入工厂来解决问题。