0

i am new to spring framework and i am getting NullPointerException when i try to use the injected dependency. Here is my code:

DemoConfig:

@Configuration
@EnableAspectJAutoProxy
@ComponentScan("com.trial.classes")
public class DemoConfig {

}

AccountDAO:

@Component
public class AccountDAO {

    @Autowired
    TestClass test;    // the problem: the object is null!


}

TestClass:

@Component
public class TestClass {
    public void testMethod()
    {
        System.out.println("this is a test method");
    }

}

Main:

public static void main(String[] args) {


        AnnotationConfigApplicationContext context =
                new AnnotationConfigApplicationContext(DemoConfig.class);


    AccountDAO theAccountDAO = context.getBean("accountDAO", AccountDAO.class);

    theAccountDAO.test.testMethod();    //NullPointerException



        context.close();
    }
Hussain
  • 53
  • 1
  • 3
  • 9

0 Answers0