我正在将我们的项目从Axis迁移到Apache CXF。我想不带弹簧地使用CXF(现在)。我使用apache CXF codegen插件生成了服务和对象,但对于某些服务却无法使用。
当我尝试公开不是由CXF codegen插件生成的服务时,它就起作用了……有人可以告诉我为什么一个在起作用,而另一个却不起作用。
首先我的web.xml
<servlet>
<display-name>SimpleCXFNonSpringServlet</display-name>
<servlet-name>SimpleCXFNonSpringServlet</servlet-name>
<servlet-class>xxx.SimpleCXFNonSpringServlet</servlet-class>
</servlet>
<servlet>
<display-name>GreetingCXFNonSpringServlet</display-name>
<servlet-name>GreetingCXFNonSpringServlet</servlet-name>
<servlet-class>xxx.GreetingCXFNonSpringServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SimpleCXFNonSpringServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>GreetingCXFNonSpringServlet</servlet-name>
<url-pattern>/greeting/*</url-pattern>
</servlet-mapping>
这是一个正在运行的Web服务。每当我访问 localhost / greeting 时,我都会获得可用的SOAP服务列表。
@WebService
public interface GreetingService {
public String helloWorld(@WebParam(name="name") String name);
}
@WebService(endpointInterface = "xxx.GreetingService", serviceName = "GreetingService")
public class GreetingServiceImpl implements GreetingService {
@Override
public String helloWorld(String name) {
return "Hello World, " + name + "!";
}
}
public class GreetingCXFNonSpringServlet extends CXFNonSpringServlet {
private static final long serialVersionUID = 1L;
@Override
public void loadBus(ServletConfig servletConfig) {
super.loadBus(servletConfig);
ServerFactoryBean factory = new JaxWsServerFactoryBean();
factory.setBus(bus);
factory.setServiceClass(GreetingService.class);
factory.setServiceBean(new GreetingServiceImpl());
factory.setAddress("/calcService");
factory.create();
}
}
这是不起作用的Web服务。每当我进入 localhost / services 时,它都会说:“未找到任何服务”。 DocumentGeneratorService类是使用apache cxf codegen插件生成的。
/**
* This class was generated by Apache CXF 3.1.18
* 2019-04-05T14:54:36.480+02:00
* Generated source version: 3.1.18
*
*/
@WebService(targetNamespace = "http://stack.nl/overflow/DocumentGenerator", name = "DocumentGeneratorService")
@XmlSeeAlso({ObjectFactory.class, xxx.ObjectFactory.class, xxx.ObjectFactory.class})
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public interface DocumentGeneratorService {
@WebMethod(action = "http://stack.nl/overflow/DocumentGenerator/DocumentGenerator/GenereerDocument")
@WebResult(name = "genereerDocumentResponse", targetNamespace = "http://stack.nl/overflow/DocumentGenerator", partName = "parameters")
public DocumentGeneratorResponse genereerDocument(
@WebParam(partName = "parameters", name = "genereerDocumentRequest", targetNamespace = "http://stack.nl/overflow/DocumentGenerator")
DocumentGeneratorRequest parameters
);
}
@WebService(endpointInterface = "xxx.DocumentGeneratorService", serviceName = "DocumentGeneratorService")
public class DocumentGeneratorServiceImpl implements DocumentGeneratorService {
@Override
public DocumentGeneratorResponse genereerDocument(DocumentGeneratorRequest parameters) {
return new DocumentGeneratorResponse();
}
}
public class SimpleCXFNonSpringServlet extends CXFNonSpringServlet {
private static final long serialVersionUID = 1L;
@Override
public void loadBus(ServletConfig servletConfig) {
super.loadBus(servletConfig);
ServerFactoryBean factory = new JaxWsServerFactoryBean();
factory.setBus(bus);
factory.setServiceClass(DocumentGeneratorService.class);
factory.setServiceBean(new DocumentGeneratorServiceImpl());
factory.setAddress("/calcService");
factory.create();
}
}
代码对我来说似乎是相同的,但显然不是。。。可能是因为DocumentService类位于作为依赖关系而包含的其他maven模块中吗?