本文介绍了在访问 webService 时获取 NullPointerException.我该如何解决的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在编写一个项目,该项目充当服务器并启动并运行可供客户端使用的服务.我的服务器应用程序是一个基于 Spring MVC 3 框架的简单 CRUD 应用程序.在名为 Person 的单个表的记录上.我的 WebServices 是 SOAP1.1 servcies,并且在我在 TomCat 上部署我的项目时处于活动状态.我可以在本地主机上访问它的 wsdl,我可以通过在 tomcat 上运行和部署该项目来访问这些 web 服务.我通过重新调整 Service 方法中的标志来测试服务.现在的问题是.如果我通过其控制器在 Web 上运行服务器应用程序,我就可以通过 Web 界面正确执行 crud.所有组件 Repository、Service DAO 都被正确注释并在网络上工作.但是当我尝试通过我的服务做同样的工作时.我得到了 Autowired 对象的 NullPointerExceptions.

I have been writing a project who acts as a server and have services up and running available to be consumed by client side.My Server application is a Simple CRUD application based on Spring MVC 3 framework. over records of a single table named Person. My WebServices are SOAP1.1 servcies and are live when once I deploy my project on TomCat. I can access its wsdl on localhost and I can these webservices by running and deploying that project over tomcat. I have tested serives by retuning flags from Service methods. Now issue is that. If I run Server application over the web through its controller, I am able to do crud through web interface properly. All the components Repository, Service DAO's are properly annotated and works over web. But when I try to do same work through my services. I get NullPointerExceptions for Autowired objects.

以下是一个例外.请帮助并在评论中表达您的想法.

Following is an exception. Please help and through your thoughts in comments.

WARN org.apache.cxf.phase.PhaseInterceptorChain  - Application {http://service.accounting.cassit.com/}personService#{http://service.accounting.cassit.com/}deletePerson has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault
    at org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:155)
    at org.apache.cxf.jaxws.AbstractJAXWSMethodInvoker.createFault(AbstractJAXWSMethodInvoker.java:86)
    at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:121)
    at org.apache.cxf.jaxws.JAXWSMethodInvoker.invoke(JAXWSMethodInvoker.java:61)
    at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:75)
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:106)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:255)
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:113)
    at org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestination.java:102)
    at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:464)
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:188)
    at org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:148)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:179)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:103)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:159)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException
    at com.cassit.accounting.service.PersonServiceImpl.deletePerson(PersonServiceImpl.java:47)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:173)
    at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:89)

查看此行并检查第 47 行或相应的 java 文件时.我开始知道我正在访问 AutoWired 属性.为什么会这样?

When look at this line and inspected line number 47 or respective java file. I come to know that I was accessing an AutoWired property. Why is it so?

Caused by: java.lang.NullPointerException
        at com.cassit.accounting.service.PersonServiceImpl.deletePerson(PersonServiceImpl.java:47)

最好的问候,

推荐答案

参见 第 4.9 节,基于注解的容器配置,在 Spring 参考中.

See Section 4.9, Annotation-based container configuration, in the Spring Reference.

重要的一点是第 4.9.1 节之前的注释,引用:

The important bit is the note right before Section 4.9.1, quoting:

仅在定义它的应用程序上下文中查找 bean 上的注解.这意味着,如果您将 <context:annotation-config/> 放在 WebApplicationContextDispatcherServlet 中,它只会检查 @Autowired beans 在您的控制器中,而不是您的服务中.参见 第 16.2 节,DispatcherServlet" 了解更多信息.

很可能你的 @Service 注释类没有被扫描;试试:

It is likely your @Service-annotated classes are not being scanned; try:

<context:component-scan base-package="your.service.package" />

这篇关于在访问 webService 时获取 NullPointerException.我该如何解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 03:49