Hi all, I have problem with @Autowired.
I have config.xml with this beans
and classPHP Code:<bean id="HeroDaoImpl" class="com.epos.kernel.spring.model.HeroDaoImpl"> </bean>
<bean id="Hero" class="com.epos.kernel.spring.model.Hero"> </bean>
in IDEA I see link near private static HeroDaoImpl heroDaoImpl; and private static Hero objHero; after click on this link I move into config.xml bean. But if I run my application I have got this exceptionPHP Code:public class MainHero {
@Autowired
@Qualifier("HeroDaoImpl")
private static HeroDaoImpl heroDaoImpl;
@Autowired
@Qualifier("Hero")
private static Hero objHero;
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("app-config.xml");
SessionFactory sessionFactory = (SessionFactory) context.getBean("sessionFactory");
objHero.setName("1231");
}
}
exception on this link objHero.setName("1231");PHP Code:Exception in thread "main" java.lang.NullPointerException
at com.epos.testspring.MainHero.main(MainHero.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:110)
why ? I have method etName, and I add @Autowired


Reply With Quote
((
