NutzCN Logo
问答 nutz的cxf插件创建多个webservice报错
发布于 2443天前 作者 qq_2d753c97 1800 次浏览 复制 上一个帖子 下一个帖子
标签:

nutz 版本 1.r.63
nutz-cxf 版本 1.r.63
创建了两个webservice,一个HelloService,一个EchoService

2018-03-09 15:43:50 [qtp2114650936-32] DEBUG org.nutz.ioc.impl.ScopeContext -Remove object 'cxfModule' from [app] 
2018-03-09 15:43:50 [qtp2114650936-32] DEBUG com.snow.mvc.LogTimeProcessor -[ GET]URI=/tyjk/ws/HelloService 874ms
2018-03-09 15:43:50 [qtp2114650936-32] WARN  org.nutz.mvc.impl.processor.FailProcessor -Error@/ws/HelloService :
org.nutz.ioc.IocException: IocBean[cxfModule] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:150)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:216)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:245)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:116)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at com.snow.mvc.LogTimeProcessor.process(LogTimeProcessor.java:21)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307)
	at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
	at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
	at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
	at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
	at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:453)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:560)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1072)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:382)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1006)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
	at org.eclipse.jetty.server.Server.handle(Server.java:365)
	at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485)
	at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:926)
	at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:988)
	at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:635)
	at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
	at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628)
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException: null
	at java.util.concurrent.ConcurrentHashMap.replaceNode(ConcurrentHashMap.java:1106)
	at java.util.concurrent.ConcurrentHashMap.remove(ConcurrentHashMap.java:1097)
	at org.apache.cxf.transport.http.DestinationRegistryImpl.removeDestination(DestinationRegistryImpl.java:67)
	at org.apache.cxf.transport.http.AbstractHTTPDestination.shutdown(AbstractHTTPDestination.java:975)
	at org.apache.cxf.endpoint.ServerImpl.destroy(ServerImpl.java:182)
	at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:226)
	at org.apache.cxf.jaxws.JaxWsServerFactoryBean.create(JaxWsServerFactoryBean.java:211)
	at org.nutz.integration.cxf.AbstractCxfModule.loadBus(AbstractCxfModule.java:139)
	at org.apache.cxf.transport.servlet.CXFNonSpringServlet.init(CXFNonSpringServlet.java:77)
	at org.nutz.integration.cxf.AbstractCxfModule._init(AbstractCxfModule.java:86)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.nutz.ioc.trigger.MethodEventTrigger.trigger(MethodEventTrigger.java:18)
	at org.nutz.ioc.weaver.DefaultWeaver.onCreate(DefaultWeaver.java:72)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:139)
	... 46 common frames omitted
13 回复

贴两个Service的代码

/**
 * helloworld
 *
 *
 * @工程: nutztest @模块:
 * 
 * @作者: tom @创建日期: 2018年3月9日
 *
 * @修改记录(修改时间、作者、原因):
 */
@WebService
public interface HelloService {
	/**
	 * 心跳
	 * 
	 *
	 * @作者: tom @创建日期: 2018年3月9日
	 * 
	 * @return
	 * 
	 * @修改记录(修改时间、作者、原因):
	 */
	public String ping();

	/**
	 * helloworld
	 * 
	 *
	 * @作者: tom @创建日期: 2018年3月9日
	 * 
	 * @param str
	 * @return
	 * 
	 * @修改记录(修改时间、作者、原因):
	 */
	public String hello(@WebParam(name = "name",targetNamespace = "http://hello.webservice.snow.com/") String name);
}
/**
 * helloworld
 *
 *
 * @工程: nutztest @模块:
 * 
 * @作者: tom @创建日期: 2018年3月9日
 *
 * @修改记录(修改时间、作者、原因):
 */
@WebService(targetNamespace = "http://hello.webservice.snow.com/",endpointInterface = "com.snow.webservice.hello.HelloService", serviceName = "HelloService")
@IocBean(name = "helloService")
// @BindingType(value = javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)
public class HelloServiceImpl implements HelloService {
	/**
	 * 心跳
	 * 
	 *
	 * @作者: tom @创建日期: 2018年3月9日
	 * 
	 * @return
	 * 
	 * @修改记录(修改时间、作者、原因):
	 */
	public String ping() {
		return "pong"; // ping --> pong 心跳回路
	}

	/**
	 * helloworld
	 * 
	 *
	 * @作者: tom @创建日期: 2018年3月9日
	 * 
	 * @param str
	 * @return
	 * 
	 * @修改记录(修改时间、作者、原因):
	 */
	 
	public String hello(String name) {
		return Json.toJson(new NutMap().setv("result", true).setv("name",name)); // 简单回显
	}
}
// 服务接口类仅需要声明一个空的@WebService,不可以加serviceName,endpointInterface
@WebService
public interface EchoService {

    // 测试一下无参,有返回值的
    String ping();

    // 测试一下有参数,有返回值
    String echo(@WebParam(name = "str") String str);
}

// 服务实现类, endpointInterface写服务接口的名字,serviceName可以自定义,建议就用接口的名字
@WebService(endpointInterface = "net.wendal.nutzbook.cxfdemo.webservice.EchoService",
        serviceName = "EchoService")
@IocBean(name = "echoService")
public class EchoServiceImpl implements EchoService {

    public String ping() {
        return "pong"; // ping --> pong 心跳回路
    }

    public String echo(String str) {
        return str; // echo就是回显
    }
}
//服务实现类, endpointInterface写服务接口的名字,serviceName可以自定义,建议就用接口的名字
@WebService(endpointInterface = "com.snow.webservice.echo.EchoService",
     serviceName = "EchoService")
@IocBean(name = "echoService")
public class EchoServiceImpl implements EchoService {

 public String ping() {
     return "pong"; // ping --> pong 心跳回路
 }

 public String echo(String str) {
     return str; // echo就是回显
 }
}

看上去没写错什么, 待我试一下

好的,谢谢大神

是有问题,正在查

多个webservice 时,依然报错
三月 22, 2018 6:05:23 下午 org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean buildServiceFromClass
信息: Creating Service {http://impl.service.module.wheather.longview.io/}EchoService from class io.longview.wheather.module.service.EchoService
三月 22, 2018 6:05:24 下午 org.apache.cxf.endpoint.ServerImpl initDestination
信息: Setting the server's publish address to be /
三月 22, 2018 6:05:25 下午 org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean buildServiceFromClass
信息: Creating Service {http://impl.service.module.wheather.longview.io/}EchoService from class io.longview.wheather.module.service.EchoService
三月 22, 2018 6:05:25 下午 org.apache.cxf.endpoint.ServerImpl initDestination
信息: Setting the server's publish address to be /
2018-03-22 18:05:25 [http-nio-80-exec-2] WARN org.nutz.mvc.impl.processor.FailProcessor - Error@/longViewService/helloWorld :
org.nutz.ioc.IocException: IocBean[myCxfModule] throw Exception when creating
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:152)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:240)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:270)
at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:116)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1539)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1495)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: Soap 1.1 endpoint already registered on address /
at org.apache.cxf.binding.soap.SoapBindingFactory.addListener(SoapBindingFactory.java:925)
at org.apache.cxf.endpoint.ServerImpl.start(ServerImpl.java:123)
at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:224)
at org.apache.cxf.jaxws.JaxWsServerFactoryBean.create(JaxWsServerFactoryBean.java:211)
at io.longview.wheather.module.AbstractCxfModule.loadBus(AbstractCxfModule.java:149)
at org.apache.cxf.transport.servlet.CXFNonSpringServlet.init(CXFNonSpringServlet.java:77)
at io.longview.wheather.module.AbstractCxfModule._init(AbstractCxfModule.java:92)
at io.longview.wheather.module.AbstractCxfModule$FM$_init$40cf01a588277bb93b47902e47d95d61.invoke(AbstractCxfModule.java)
at org.nutz.ioc.impl.ObjectMakerImpl$2.trigger(ObjectMakerImpl.java:180)
at org.nutz.ioc.weaver.DefaultWeaver.onCreate(DefaultWeaver.java:89)
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:141)
... 29 more

修复方法如下,

@Override
    protected void loadBus(ServletConfig sc) {
        super.loadBus(sc);
        Bus b = getBus();
        BusFactory.setDefaultBus(b);
        JaxWsServerFactoryBean sfb = new JaxWsServerFactoryBean();
        // 首先,拿到ioc容器
        for (Class<?> klass : Scans.me().scanPackage(pkg, null))
        {
            // 有@WebService和@IocBean注解的非接口类
            WebService ws = klass.getAnnotation(WebService.class);
            if (ws == null || klass.isInterface()) continue;
            if (Strings.isBlank(ws.serviceName()))
            {
                log.infof("%s has @WebService but serviceName is blank, ignore", klass.getName());
                continue;
            }
            log.debugf("add WebService addr=/%s type=%s", ws.serviceName(), klass.getName());
            // Endpoint.publish("/" + ws.serviceName(), ioc.get(klass));
           
            sfb.setServiceBean(ioc.get(klass));
            sfb.setBus(b);
            sfb.setAddress("/" + ws.name());
           
            // System.out.println(sfb.getAddress());
        }
        sfb.create();
    }

改了哪个地方??

JaxWsServerFactoryBean sfb = new JaxWsServerFactoryBean();
for(){
.............................
}
sfb.create();
移到for 外层

这样就只启动了一个吧?

添加回复
请先登陆
回到顶部