I'm trying to test the Autowire option like this:
@ContextConfiguration(locations = { "classpath:applnContext.xml" })
public class Foo {
@Autowired
private Bar bar;
public Bar getBar() {
return bar;
}
public void setBar(final Bar bar) {
this.bar = bar;
}
public static void main(final String[] args) {
final Foo f = new Foo();
System.out.println(f.getBar());
}
}
and the config file :
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="bar" class="entity.Bar"></bean>
<context:annotation-config />
</beans>
But the Bar
object is not getting injected. Am I missing anything here or doing something wrong?
Note that I'm specifying the applicationContext file using annotation on the class.