开发者

Spring Dependency not working with Webservices

开发者 https://www.devze.com 2023-04-06 20:29 出处:网络
I have exposed a service in application as Webservice, but it is not getting handal to a Dao which is injected through Dao, any one has any idaa?

I have exposed a service in application as Webservice, but it is not getting handal to a Dao which is injected through Dao, any one has any idaa? Stack

Sep 23, 2011 6:48:58 PM com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException SEVERE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container java.lang.NullPointerException at com.scor.omega2.reference.services.impl.CurrencyServiceImpl.getCurrency(CurrencyServiceImpl.java:33) at com.scor.omega2.reference.services.impl.CurrencyServiceImpl.getCurrency(CurrencyServiceImp开发者_如何转开发l.java:41) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60) at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)

Code

@Path("/currency")
@Named("currencyService")
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class CurrencyServiceImpl implements CurrencyService {

    @Inject
    private CurrencyDao currencyDao;

    /**
     * Service to get Currency Code Value
     * 
     * @param cur_cf
     * @param lag_cf
     * @return entity.
     */
    public BrefTcurl getCurrency(String cur_cf, char lag_cf) {
        return currencyDao.getCurrency(cur_cf, lag_cf);
    }

    @GET
    @Produces( { MediaType.APPLICATION_XML})
    @Path("{cur_cf}/{lag_cf}")
    public BrefTcurl getCurrency(@PathParam("cur_cf") String cur_cf, @PathParam("lag_cf") String lag_cf) {
        System.out.println("cur_cf "+cur_cf +" lag_cf "+lag_cf);
        return getCurrency(cur_cf,lag_cf.charAt(0));
    }
}

Currency Dao Class

@Named("currencyDao")
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class CurrencyDaoImpl implements CurrencyDao
{

@PersistenceContext
private EntityManager entityManager;

/**
 * Service to get Currency Code Value
 * 
 * @param cur_cf
 * @param lag_cf
 * @return entity.
 */
public BrefTcurl getCurrency(String cur_cf, char lag_cf)
{
    return entityManager.find(BrefTcurl.class, new BrefTcurlId(lag_cf, cur_cf));
}

}


I think the servlet you have configured in web.xml is the wrong one. You need to use the one that is aware of spring and delegates to spring managed beans for processing the request.

com.sun.jersey.spi.spring.container.servlet.SpringServlet
0

精彩评论

暂无评论...
验证码 换一张
取 消