简体   繁体   中英

How to access DAO from Webservice using JAX-WS

Just started using JAX-WS. I created service class and DAO class. My service is running fine but it gives NullPointerExeption b'coz it can't locate to DAO; I am trying to call to DAO from service class:

package com.nmmc.works.service.impl;
@WebService(serviceName="MyService")
public class SecurityServiceImpl extends GenericServiceImpl implements ISecurityService
{   
    private ISecurityDAO securityDAO;

....getter setter methods....

@WebMethod
    public Integer getBidAcceptanceIdForSDPayment(Integer tMastNo)
    {   
        InternalResultsResponse<Object> response = getSecurityDAO().getMyMethod(tenderMastNo);
        if(response != null && response.getResultsList().size() > 0){
            return Integer.parseInt(response.getFirstResult().toString());  
        }else{
            return -1;
        }

    }

And sun-jaxws.xml.....

<b>
<?xml version="1.0" encoding="UTF-8"?>
    <endpoints version="2.0" xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime">
      <endpoint 
          implementation="com.nmmc.works.service.impl.SecurityDepositServiceImpl"

          name="MyServices" 
          url-pattern="myPath/SecurityServiceImpl"
          />
    </endpoints></b>

In web.xml....

<b><listener>
      <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>WebServices</servlet-name>
        <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
        <load-on-startup>2</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>WebServices</servlet-name>
        <url-pattern>/ws/*</url-pattern>
    </servlet-mapping></b>

Your SecurityServiceImpl doesn't have a DAO in it when you run it. You'll have to ensure that a DAO is properly created and injected into/obtained by it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM