I\'m trying to understand DI, but my spring bean is not injected or created when I use the autowire and component annotations. Instead I get a nullpointer exception because my b
Try to add
<context:annotation-config/>
to your Spring config file.
You're only creating a BeanFactory, which has extremely limited functionality. It really does nothing more than instantiate beans and let you manually wire them together. The functionality you're looking for only exists in ApplicationContexts, which is really Spring's bread and butter. Change
BeanFactory factory = new XmlBeanFactory(
new ClassPathResource("application-context.xml"));
to
BeanFactory factory = new ClassPathXmlApplicationContext(
"application-context.xml");
Then read "The BeanFactory" to get familiar with the distinction.