cancel
Showing results for 
Search instead for 
Did you mean: 

activiti spring test

parul_vipparthi
Champ on-the-rise
Champ on-the-rise
Hello

I am new to Spring. This code gives nullpointerexception.


@ContextConfiguration("classpath:org/activiti/spring/test/gal_example/springTest-context.xml")
public class SpringTest{

   ProcessEngine processEngine;
   @Autowired
   ApplicationContext applicationContext;
        void initializeProcessEngine() {
        System.out.println("  " + applicationContext);
         processEngine = applicationContext.getBean(ProcessEngine.class);
        System.out.println("  " + processEngine);
     }

     public static void main(String[] args) {
      new SpringTest().initializeProcessEngine();
   }
}

but this code works fine

public class SpringTest{

   ProcessEngine processEngine;
     void initializeProcessEngine() {
        ClassPathXmlApplicationContext applicationContext =
             new ClassPathXmlApplicationContext("org/activiti/spring/test/gal_example/springTest-context.xml");
        System.out.println("  " + applicationContext);
         processEngine = applicationContext.getBean(ProcessEngine.class);
        System.out.println("  " + processEngine);
     }

     public static void main(String[] args) {
      new SpringTest().initializeProcessEngine();
   }
}

what went wrong?

Thank you
1 REPLY 1

frederikherema1
Star Contributor
Star Contributor
The annotations aren't picked up when you just run the main method of the test.

You should use the test and run it with JUnit, that way the test will get the application context injected.