我正在使用 Spring 和 Apache CXF 实现现有接口(interface)的另一个实现。当tomcat启动时,它显示以下错误消息:
Method getSomething in ModuleInterface has no JAX-RS Path or HTTP Method annotations
并且,两个端点都返回 404。
我不确定我错过了什么。有人知道吗?
public interface ModuleInterface {
public Response getSomething(@Valid RequestObj obj);
}
--
@Service
@Path("/foo")
public class FooClass implements moduleInterface {
public Response getSomething(@Valid Request obj){
// code
}
}
--
@Service
@Path("/new/foo")
public class FooV2Class implements moduleInterface {
public Response getSomething(@Valid Request obj){
// code
}
}
--
@Configuration
@ImportResource({"classpath:/META-INF/cxf/cxf-servlet.xml", "classpath:/META-INF/cxf/cxf.xml"})
public class APIConfig {
@Autowired @Lazy ModuleInterface moduleInterface;
@Bean
public Server initCxfServer(){
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setServiceBeanObjects(getJaxRsResources());
sf.setProviders(Arrays.asList(
new JacksonJaxbJsonProvider()
));
return sf.create();
}
private Object[] getJaxRsResources() {
return new Object[]{
moduleInterface
};
}
private HashMap getExtMaps() {
return new HashMap<String,String>(){{
put("json","application/json;charset=utf-8");
put("xml","application/xml;charset=utf-8");
put("wadl","application/vnd.sun.wadl+xml");
put("desc","application/vnd.sun.desc+json;charset=utf-8");
}};
}
最佳答案
如果您使用 @Valid
(甚至其他注释,例如 @Context
)对接口(interface)和实现类中的两个方法中的参数进行注释,则可能会发生这种情况.
仅在使用 @Path 注释的方法的参数上保留注释(无论是在接口(interface)中,还是在实现类中),它应该可以工作。
关于java - JAX-RS 方法没有 Path 或 HTTP 方法注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33023730/