AnsweredAssumed Answered

spring dependency injection issue

Question asked by pmarreddy on Jan 16, 2006
Latest reply on Jan 16, 2006 by pmarreddy
hi,

we are exploring alfreco for a while, its a great product, we are considering to provide content services which would have been very difficult with out alfresco.

i have some issues in trying to use spring dependency injection, it would be great if somebody can figure out the solution.

<bean id="initTest" class="org.alfresco.example.inittest"  >
       <property name="authenticationService">
            <ref bean="authenticationService" />
        </property>
        </bean>
</beans>



i have defined this in application-context.xml in repository and used it in the following way.


package org.alfresco.example;

import org.alfresco.service.cmr.security.AuthenticationService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


public class inittest {
   
      private AuthenticationService authenticationService;
     
      public void setAuthenticationService(AuthenticationService authenticationService)
      {
        System.out.println("hi");
        this.authenticationService = authenticationService;
      }
    
      public void login() throws Exception
      {
        
        
         ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:alfresco/application-context.xml");
        
         authenticationService.authenticate("admin", "admin".toCharArray());
      }
}

i am getting

Exception in thread "main" java.lang.NullPointerException
   at org.alfresco.example.inittest.login(test1.java:23)
   at org.alfresco.example.loggie.main(loggie.java:14)

Outcomes