NutzCN Logo
问答 CXF接口报错,兽兽哥请看?
发布于 3219天前 作者 qq_6427b776 2061 次浏览 复制 上一个帖子 下一个帖子
标签:

2016-03-01 10:24:59,705 cn.com.venustech.webservices.servlet.CXFServlet.loadBus(CXFServlet.java:63) ERROR - webService异常
java.lang.NullPointerException
at cn.com.venustech.webservices.servlet.CXFServlet.loadBus(CXFServlet.java:41)
at org.apache.cxf.transport.servlet.CXFNonSpringServlet.init(CXFNonSpringServlet.java:76)
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:612)
at org.eclipse.jetty.servlet.ServletHolder.initialize(ServletHolder.java:395)
at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:871)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:298)
at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1349)
at org.eclipse.jetty.maven.plugin.JettyWebAppContext.startWebapp(JettyWebAppContext.java:296)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1342)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:741)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:505)
at org.eclipse.jetty.maven.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:365)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:163)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
at org.eclipse.jetty.server.Server.start(Server.java:387)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
at org.eclipse.jetty.server.Server.doStart(Server.java:354)
at org.eclipse.jetty.maven.plugin.JettyServer.doStart(JettyServer.java:73)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.maven.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:534)
at org.eclipse.jetty.maven.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:357)
at org.eclipse.jetty.maven.plugin.JettyRunMojo.execute(JettyRunMojo.java:167)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:347)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:582)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
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:483)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

17 回复

看这行代码

java.lang.NullPointerException
at cn.com.venustech.webservices.servlet.CXFServlet.loadBus(CXFServlet.java:41)

package cn.com.venustech.webservices.servlet;

import javax.jws.WebService;
import javax.servlet.ServletConfig;

import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
import org.apache.cxf.frontend.ServerFactoryBean;
import org.apache.cxf.transport.servlet.CXFNonSpringServlet;
import org.nutz.ioc.Ioc;
import org.nutz.lang.Strings;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.Mvcs;

/**
* WebService启动类
*
* @author lanxianghua
*/
@SuppressWarnings("serial")
public class CXFServlet extends CXFNonSpringServlet {
private final Log log = Logs.get();

@SuppressWarnings("rawtypes")
@Override
protected void loadBus(ServletConfig sc) {
    super.loadBus(sc);

    // 全局配置
    Bus bus = getBus();
    // 添加白名单过滤器
    // bus.getInInterceptors().add(new IpAddressInInterceptor());
    // 使用全局配置
    BusFactory.setDefaultBus(bus);

    Ioc ioc = Mvcs.ctx().getDefaultIoc();
    for (String name : ioc.getNames()) {
       try {
         Object obj = ioc.get(null, name);
         if (!obj.getClass().getPackage().getName()
              .equals("cn.com.venustech.webservices.server.impl")) {
          continue;
         }
         if (obj.getClass().getAnnotation(WebService.class) == null) {
          continue;
         }
         String clazz = "cn.com.venustech.webservices.server."
              + Strings.upperFirst(name);
         log.info("加载服务:" + clazz);
         Class face = Class.forName(clazz);
         ServerFactoryBean serverFactoryBean = new ServerFactoryBean();
         // 设置服务接口类
         serverFactoryBean.setServiceClass(face);
         // 服务请求路径
         serverFactoryBean.setAddress("/"
              + name.substring(0, name.indexOf("Service")));
         // 设置服务实现类
         serverFactoryBean.setServiceBean(obj);
         // serverFactoryBean.setBindingId("http://schemas.xmlsoap.org/wsdl/soap12/");
         serverFactoryBean.create();
       } catch (Throwable e) {
         log.error("webService异常", e);
       }
    }
}

}

大哥

ioc.get(null,name)

能取到数据么?

断点不了,可以远程帮我控制吗?

@qq_6427b776
你需要传类型进去 而不是传null

@qq_6427b776
@qq_6427b776
你是不是要扫描某个包下的类?

obj.getClass().getPackage().getName() 能出NPE错误的只能是两种情况了:

  1. obj是null
  2. obj所属的没有package

两种情况,打印一下日志就知道啦

@wendal 这个应该如何排查呢?打断点都不行?

@Rekoe 你有QQ吗?你能否帮我远程计算机操作一下我的项目看看?
我的QQ是3045707312

@Rekoe 主要进入接口入口,都无法断点调试了,所以很难发现问题?

@qq_6427b776 等下 现在开会

来自 iPhone 6

@Rekoe 好,我等你,你QQ多少,我加你QQ先?

@Rekoe 我打印过,有取到数据

@qq_6427b776
5382211

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