Spring依赖关系不适用于Web服务

时间:2011-09-23 17:00:32

标签: web-services spring jaxb

我已经在应用程序中公开了一个服务作为Webservice,但它没有得到通过Dao注入的Dao,任何人有任何idaa? 堆

  

2011年9月23日下午6:48:58 com.sun.jersey.spi.container.ContainerResponse   mapMappableContainerException SEVERE:RuntimeException不能   被映射到响应,重新投掷到HTTP容器   java.lang.NullPointerException at   com.scor.omega2.reference.services.impl.CurrencyServiceImpl.getCurrency(CurrencyServiceImpl.java:33)     在   com.scor.omega2.reference.services.impl.CurrencyServiceImpl.getCurrency(CurrencyServiceImpl.java:41)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(未知来源)at   sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)at   java.lang.reflect.Method.invoke(未知来源)at   com.sun.jersey.spi.container.JavaMethodInvokerFactory $ 1.invoke(JavaMethodInvokerFactory.java:60)     在   com.sun.jersey.server.impl.model.method.dispatch.Abs​​tractResourceMethodDispatchProvider $ TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)

代码

@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));
    }
}

货币Dao类

@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));
}

}

1 个答案:

答案 0 :(得分:0)

我认为您在web.xml中配置的servlet是错误的。您需要使用知道spring的那个并委托spring spring Bean来处理请求。

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