NutzCN Logo
问答 把某个方法暴露为webservice时,关于注入的dao为空的问题
发布于 2375天前 作者 qq_7fafbecc 2679 次浏览 复制 上一个帖子 下一个帖子
标签:

接口:

@WebService(targetNamespace = "http://interf.service.blood.shlx.com", serviceName = "PdaService")
public interface PdaService {

	@WebResult(name = "return", targetNamespace = "http://interf.service.blood.shlx.com")
	@WebMethod(action = "http://interf.service.blood.shlx.com/doReceipt")
	public String doReceipt(
			@WebParam(name="BagCode",targetNamespace="http://interf.service.blood.shlx.com") String BagCode,
			@WebParam(name="CheckerCode",targetNamespace="http://interf.service.blood.shlx.com") String CheckerCode,
			@WebParam(name="SingerCode",targetNamespace="http://interf.service.blood.shlx.com") String SingerCode,
			@WebParam(name="DepartmentCode",targetNamespace="http://interf.service.blood.shlx.com") String DepartmentCode
						   ) ;

	
}

接口实现:

@WebService(endpointInterface="com.shlx.blood.service.interf.PdaService",serviceName="PdaService")
@IocBean
public class PdaServiceImpl implements PdaService {
	
	private final Log log = Logs.get();
	
	@Inject    
    protected Dao dao; 
	
	@Inject    
    protected PdaServiceBo pdaServiceBo; 

	@Aop(TransAop.READ_COMMITTED)
	@Override
	public String doReceipt(String BagCode,String CheckerCode,String SingerCode,String DepartmentCode){

		NutMap returnMap = new NutMap();
		//执行结果代号--出参
		int ReturnCode = -999;
		//执行结果描述--出参
	    String ReturnText = "无";      
		
		Sql sql = Sqls.create("{CALL PDA_SCAN_BAGCODE(@BagCode,@CheckerCode,@SingerCode,@DepartmentCode,@OUTReturnCode,@OUTReturnText)}");
	    sql.setEntity(dao.getEntity(Record.class));
	    sql.params().set("BagCode", BagCode); // 设置入参
	    sql.params().set("CheckerCode", CheckerCode); // 设置入参
	    sql.params().set("SingerCode", SingerCode); // 设置入参
	    sql.params().set("DepartmentCode", DepartmentCode); // 设置入参
	    sql.params().set("OUTReturnCode", Types.INTEGER);// 设置出参类型,注意,必须加OUT开头
	    sql.params().set("OUTReturnText", Types.VARCHAR);// 设置出参类型,注意,必须加OUT开头
	    dao.execute(sql);
	    Record re = sql.getOutParams();
	    ReturnCode = re.getInt("returncode");
	    ReturnText = re.getString("returntext");
	    returnMap.put("ReturnCode", ReturnCode);
	    returnMap.put("ReturnText", ReturnText);
	    //return ReturnText;
	    return Json.toJson(returnMap);

	}
	
	
}

后台客户端模拟调用webservice后:

开始获取数据。。。
Exception in thread "main" com.sun.xml.internal.ws.fault.ServerSOAPFaultException: Client received SOAP Fault from server: Fault occurred while processing. Please see the server log to find more detail regarding exact cause of the failure.
	at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(Unknown Source)
	at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(Unknown Source)
	at com.sun.xml.internal.ws.client.sei.StubHandler.readResponse(Unknown Source)
	at com.sun.xml.internal.ws.db.DatabindingImpl.deserializeResponse(Unknown Source)
	at com.sun.xml.internal.ws.db.DatabindingImpl.deserializeResponse(Unknown Source)
	at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)
	at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)
	at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(Unknown Source)
	at com.sun.proxy.$Proxy31.doReceipt(Unknown Source)
	at com.shlx.blood.service.interf.Client.main(Client.java:8)

3 回复

尝试过调试,把

sql.setEntity(dao.getEntity(Record.class));

加上注解,就不报错,
而解开注解,就会报错
怀疑是dao是Null,没有注入进来,怎么弄呢

这样也不报错:

	    String ReturnText = "无";      
		
		Sql sql = Sqls.create("{CALL PDA_SCAN_BAGCODE(@BagCode,@CheckerCode,@SingerCode,@DepartmentCode,@OUTReturnCode,@OUTReturnText)}");
	    //sql.setEntity(dao.getEntity(Record.class));
	    sql.params().set("BagCode", BagCode); // 设置入参
	    sql.params().set("CheckerCode", CheckerCode); // 设置入参
	    sql.params().set("SingerCode", SingerCode); // 设置入参
	    sql.params().set("DepartmentCode", DepartmentCode); // 设置入参
	    sql.params().set("OUTReturnCode", Types.INTEGER);// 设置出参类型,注意,必须加OUT开头
	    sql.params().set("OUTReturnText", Types.VARCHAR);// 设置出参类型,注意,必须加OUT开头
	    /*dao.execute(sql);
	    Record re = sql.getOutParams();
	    ReturnCode = re.getInt("returncode");
	    ReturnText = re.getString("returntext");
	    returnMap.put("ReturnCode", ReturnCode);
	    returnMap.put("ReturnText", ReturnText);*/
	    return ReturnText;
	    //return Json.toJson(returnMap);

估计是dao为空

何须估计,打印一下dao变量就知道是不是null啦。。。

是cxf吗?

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