NutzCN Logo
问答 webservice 服务端调用service 空指针异常
发布于 2279天前 作者 qq_cff0990a 3873 次浏览 复制 上一个帖子 下一个帖子
标签:

如题,调用service存入list报错

查询数据库

public List getBankRecordFromDataBase() {

		NutMap re = new NutMap();
		Sql sql = Sqls.create("SELECT * FROM bank_record_detail");
		System.out.println(sql);
		sql.setCallback(new SqlCallback() {
			public Object invoke(Connection conn, ResultSet rs, Sql sql) throws SQLException {
				List<bank_record_detail> list = new ArrayList<bank_record_detail>();
				while (rs.next()) {
					bank_record_detail b = new bank_record_detail();
					b.setAccount(rs.getString("account"));
					b.setAccountType(rs.getString("accounttype"));
					b.setId(rs.getString("id"));

					list.add(b);
				}
				return list;
			}
		});
		dao().execute(sql);
		List<String> list = sql.getList(String.class);

		return list;
	}


package cn.wizzer.common.webservice;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.nutz.dao.Dao;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.By;
import org.nutz.mvc.annotation.Filters;

import cn.wizzer.common.filter.PrivateFilter;
import cn.wizzer.common.util.ListToXml;
import cn.wizzer.modules.back.reconciliation.models.bank_record_detail;

import cn.wizzer.modules.back.reconciliation.services.bank_record_detailService;
import cn.wizzer.modules.back.sw.services.PrisonInformationService;
import net.sf.ehcache.search.Results;
@IocBean
@WebService
@Filters({@By(type = PrivateFilter.class)})
public class WebImpl implements Web{

@Inject
PrisonInformationService prisoninformationservice;

@Inject
Dao dao;
private ListToXml lox = new ListToXml();

@Override
@WebMethod
public String xml_test(String words) {
    String ars="<resultRow>\r\n" + 
         "      <result comment=\"JYDM\" property=\"JYDM\">2201</result>\r\n" + 
         "      <result comment=\"JYMC\" property=\"JYMC\">��������</result>\r\n" + 
         "      <result comment=\"STRUCTURE_CODE\" property=\"STRUCTURE_CODE_NEW\">22010001</result>\r\n" + 
         "      <result comment=\"ELEMENT_ID\" property=\"ELEMENT_ID\">8a8081863efeeaab013efeeaab940000</result>\r\n" + 
         "      <result comment=\"ELEMENT_ORDER\" property=\"ELEMENT_ORDER\">2</result>\r\n" + 
         "    </resultRow>";

    return ars;
}
@WebMethod
public String sayHi(@WebParam(name = "text") String text) {
    return "Hello,"+text;
}


/**
 * @return
 * @throws Exception
 */

@RequiresAuthentication
public String fromBean() throws Exception {

    List list ;

//此处报错
list = prisoninformationservice.getBankRecordFromDataBase();
String x = lox.parseNodeToXML(list);
return x;

}

}


异常 日志

严重: null
java.lang.NullPointerException
at cn.wizzer.common.webservice.WebImpl.fromBean(WebImpl.java:66)
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 sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
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 sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
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 com.sun.xml.internal.ws.api.server.MethodUtil.invoke(MethodUtil.java:68)
at com.sun.xml.internal.ws.api.server.InstanceResolver$1.invoke(InstanceResolver.java:235)
at com.sun.xml.internal.ws.server.InvokerTube$2.invoke(InvokerTube.java:134)
at com.sun.xml.internal.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:73)
at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:1121)
at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:1035)
at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:1004)
at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:862)
at com.sun.xml.internal.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:404)
at com.sun.xml.internal.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:706)
at com.sun.xml.internal.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:260)
at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handleExchange(WSHttpHandler.java:98)
at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handle(WSHttpHandler.java:82)
at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:79)
at sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:83)
at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:82)
at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:675)
at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:79)
at sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:647)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

```

10 回复
 at cn.wizzer.common.webservice.WebImpl.fromBean(WebImpl.java:66)

66行是哪一行

@wendal list = prisoninformationservice.getBankRecordFromDataBase(); 这个

所以prisoninformationservice是null了, 注入没有生效

cxf做的webservice??

这个webservice用什么代码启动的???

@wendal

package cn.wizzer.common.webservice;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.xml.ws.Endpoint;

public class StartFilter implements Filter {

    public void destroy() {

    }

    public void doFilter(ServletRequest arg0, ServletResponse arg1,
            FilterChain arg2) throws IOException, ServletException {

    }

    public void init(FilterConfig arg0) throws ServletException {
        this.startWebsocketInstantMsg();
    }

    /**
     * 启动即时聊天服务
     */
    public void startWebsocketInstantMsg() {
        
        System.err.println("websocket启动了");
        //启动webservice
        Endpoint.publish("http://192.168.1.112:8085/ws_server/weather", new WebImpl());
        System.out.println("webservice启动了");
    }
}

Web web = Mvcs.ctx().getDefaultIoc().get(WebImpl.class);
Endpoint.publish("http://192.168.1.112:8085/ws_server/weather", web);

@wendal 注入进去了 可以简单解释一下原理吗 感激不尽

直接new对象是没有"注入"一说的

@wendal 明白了 ,之前的误区在以为是service没注入,其实是webservice的实现类没注入进去,学习了 感谢!

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