2016-11-10 7 views
0

メールアドレスのユーザー名とランダムなパスワードを生成するために、AlfrescoのCreateUserHandlerという名前でクラスを作成しました。これはおそらくですアルフレコで次のコードを正しく動作させるにはどうすればいいですか?

Nov 10, 2016 4:46:33 PM org.apache.catalina.core.StandardContext listenerStart 
SEVERE: Exception sending context initialized event to listener instance of class org.alfresco.repo.webdav.WebDAVSessionListener 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.eisenvault.autoMailgenerate.createUserHandler' defined in class path resource [alfresco/module/demoact1-repo/context/service-context.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.eisenvault.autoMailgenerate.CreateUserHandler]: Constructor threw exception; nested exception is java.lang.NullPointerException 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1038) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:984) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:487) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:633) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) 
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:410) 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) 
    at org.alfresco.web.app.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:63) 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939) 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at java.lang.Thread.run(Thread.java:745) 
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.eisenvault.autoMailgenerate.CreateUserHandler]: Constructor threw exception; nested exception is java.lang.NullPointerException 
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163) 
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1031) 
    ... 23 more 
Caused by: java.lang.NullPointerException 
    at com.eisenvault.autoMailgenerate.CreateUserHandler.<init>(CreateUserHandler.java:30) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422) 
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148) 
    ... 25 more 
+0

'alfresco/module/demoact1-repo/context/service-context.xml'ファイルの内容を表示してください。 – wildloop

+0

私はあなたがJavaとSpring IoCの基礎を学ぶべきだと思うhttp://docs.spring.io/spring/docs/current/spring-framework-reference/html/beans.html – wildloop

+0

[新しいユーザーの作成時にユーザー名とランダムパスワード](http://stackoverflow.com/questions/40625577/auto-generation-of-email-with-username-and-random-password-on-creation-of-new-us ) – wildloop

答えて

3

:私は、私はまた、ヌル・ポインタ例外のログスタックトレースを取り付ける...

public class CreateUserHandler { 
    private static Logger logger = LoggerFactory.getLogger(CreateUserHandler.class); 
    private NodeService nodeService = getServiceRegistry().getNodeService(); 
    private PersonService personService = getServiceRegistry() 
       .getPersonService(); 
    private ActionService actionService = getServiceRegistry() 
       .getActionService(); 
    private SearchService searchService = getServiceRegistry() 
       .getSearchService(); 

     private PolicyComponent eventManager; 
     private ServiceRegistry serviceRegistry; 
     //private String userName; 

     public void setServiceRegistry(ServiceRegistry serviceRegistry) { 
      this.serviceRegistry = serviceRegistry; 
     } 

     private ServiceRegistry getServiceRegistry() { 
      // TODO Auto-generated method stub 
      return null; 
     } 

     public void setPolicyComponent(PolicyComponent policyComponent) { 
      this.eventManager = policyComponent; 
     } 

     public void registerEventHandlers() { 
      eventManager.bindClassBehaviour(
        NodeServicePolicies.OnCreateNodePolicy.QNAME, 
        ContentModel.TYPE_USER, 
        new JavaBehaviour(this, "onaddUser", 
          Behaviour.NotificationFrequency.EVERY_EVENT)); 


     } 
     protected String userName = null; 
     protected String password = null; 
     /** 
     * Get user password 
     * @return user password 
     */ 
     public String getPassword() { 
      return password; 
     } 

     /** 
     * Set user password 
     * @param password user password 
     */ 
     public void setPassword(String password) { 
      this.password = password; 
     } 


     public void onaddUser(ChildAssociationRef parentChildAssocRef) { 
      //new PersonService().setPersonProperties(userName, properties); 
      System.out.println("Creation of user successfully completed"); 

      //NodeRef userNodeRef; 
      // String sTempUserName = this.userName; 
      NodeRef person = null; 
      String username = (String) serviceRegistry.getNodeService().getProperty(person,ContentModel.PROP_USERNAME); 



        System.out.println("Username got :" + username); 

         if (personService.personExists(username)) { 

          //NodeRef person = personService.getPerson(sTempUserName); 
          person = personService.getPerson(username); 

          String address = (String) nodeService.getProperty(person, 

             ContentModel.PROP_EMAIL); 

          if (address != null && address.length() != 0) { 

            // recipients.add(address); 

            System.out.println("Email Address is :" + address); 
            String newPassword = Password.generatePassword(); 

            char[] cadChars = new char[newPassword.length()]; 

            for (int i=0; i<newPassword.length(); i++) 
            { 
            cadChars[i] = newPassword.charAt(i); 
            } 
            // Save new password 
            serviceRegistry.getAuthenticationService().setAuthentication(username, newPassword.toCharArray()); 
            // Save new password 
            setPassword(newPassword); 
            System.out.println("Password is :" + newPassword); 

          } 

         } 
       } 




} 

を誰かがこれで私を助けてthis..Pleaseで例外を取得しています

private ServiceRegistry getServiceRegistry() { 
     // TODO Auto-generated method stub 
     return null; 
    } 

private PersonService personService = getServiceRegistry() 
      .getPersonService(); 
の0

その結果、NPEがスローされます。 getServiceRegistry()は常にnullを返す場合

+0

私はそれを公開するか保護しますか?どのような変更を行う必要がありますか? – APM

+0

ただ削除してください。あなたは、あなたがxml構成でそのオブジェクトを注入したと仮定して、それを必要としません。ちょうどserviceRegistryを使用してください – zawhtut

+0

私はまだnullポインタの例外を取得しています。誰かがフォーマットされたコードで私を助けることができます – APM

0

この

private NodeService nodeService = getServiceRegistry().getNodeService(); 

は動作しません。

最も簡単な方法はpersonServiceactionService、およびsearchServiceために同じことを行いメンバーnodeServiceを削除し、

String address = (String) serviceRegistry.getNodeService().getProperty(person, ContentModel.PROP_EMAIL); 

String address = (String) nodeService.getProperty(person, ContentModel.PROP_EMAIL); 

ような行を変更することです。

+0

まだ成功しているnullポインタ – APM

関連する問題