2016-08-03 36 views
0

我是新來的露天社區,我通過使用java在戶外社區創建了人員。如何通過java獲取露天分享的人?

但現在我想通過使用java來獲取該用戶數據。我想下面,但它引發空指針異常。

PersonServiceImpl personServiceImpl = new PersonServiceImpl(); 
     NodeRef nodeRef = personServiceImpl.getPerson("sobhan"); 
     System.out.println("Person Service imple "+nodeRef); 

錯誤是

Aug 03, 2016 5:43:32 PM org.apache.catalina.core.ApplicationContext log 
INFO: Initializing Spring FrameworkServlet 'testing' 
+========================================== 
uplaod file 
Aug 03, 2016 5:43:58 PM org.apache.catalina.core.StandardWrapperValve invoke 
SEVERE: Servlet.service() for servlet [testing] in context with path [/SpringWithAlfrescoScreens] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause 
java.lang.NullPointerException 
    at org.alfresco.repo.security.person.PersonServiceImpl.getFromCache(PersonServiceImpl.java:1827) 
    at org.alfresco.repo.security.person.PersonServiceImpl.getPersonOrNullImpl(PersonServiceImpl.java:530) 
    at org.alfresco.repo.security.person.PersonServiceImpl.getPersonImpl(PersonServiceImpl.java:489) 
    at org.alfresco.repo.security.person.PersonServiceImpl.getPerson(PersonServiceImpl.java:476) 
    at org.alfresco.repo.security.person.PersonServiceImpl.getPerson(PersonServiceImpl.java:433) 
    at com.plianto.dmsservice.DummyDmsService.perm(DummyDmsService.java:70) 
    at com.service.AlfService.saveApplication(AlfService.java:116) 
    at com.controller.AlfController.saveApplication(AlfController.java:146) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221) 
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137) 
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) 
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:777) 
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:706) 
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) 
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943) 
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877) 
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966) 
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621) 
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) 
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) 
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041) 
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603) 
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
    at java.lang.Thread.run(Thread.java:745) 
+1

你不應該創建一個新的'PersonServiceImpl',但在配置中注入現有的。 – Walfrat

+0

對不起,我不瞭解你說的。請清楚告訴我.. – Manohar

+1

他意味着PersonServiceImpl是一個Spring Bean。你應該在你的類中注入它,而不是創建一個新的PersonServiceImpl()。 – Akah

回答

1

我繼續在這裏回答,因爲它是很難在評論郵編:

正如Walfrat說:

你不應該創建一個新的PersonServiceImpl但 注入配置中的現有人。

因爲人服務是由Spring處理的。

在你的背景文件,爲您服務com.plianto.dmsservice.MyService,你應該聲明現有的人服務是這樣的:

<bean id="dummyDmsService" class="com.plianto.dmsservice.DummyDmsService"> 
    <property name="personService"> 
     <ref bean="PersonService" /> 
    </property> 
</bean> 

然後在你的類:

public class DummyDmsService{ 
    private PersonService personService; 

    /** 
    * @return the personService 
    */ 
    public final PersonService getPersonService() { 
     return personService; 
    } 

    /** 
    * @param pPersonService 
    *   the personService to set 
    */ 
    public final void setPersonService(final PersonService pPersonService) { 
     personService = pPersonService; 
    } 
    ... 
} 
+0

現在我得到了「沒有名爲'personService'的bean被定義爲」 – Manohar

+0

你是否在露天情況下?您是否使用了Personcase的大寫字母? – Akah

+0

對不起,請告訴我如何得到露天的環境... – Manohar