Home > Back-end > Getbean can injection, but not autowired, who help me, please
Getbean can injection, but not autowired, who help me, please
Time:09-27
I recently learned spring and mybatis integration, found autowired can't use, is a null pointer, but when using the ClassPathXmlApplicationContext before can be getbean, then I wrote a test, the result is not, asking our bosses help,
@ Component @ ComponentScan Public class test { The @autowired Private Master m; Private Master m2;
@ Test Public void test1 () { ClassPathXmlApplicationContext ac=new ClassPathXmlApplicationContext (" beans. XML "); M2=(Master) ac) getBean (" m "); If (m==null) System. The out. Println (" autowired failure "); If (m2==null) System. The out. Println (" getbean failure "); }
}
Then I XML is scan and beans, and then the bean class is I find from the model, there is a entity class,
Request is very confused,,,, help me have a look
CodePudding user response:
What do you call a injection is assigned to a no injection, the ioc could not find the m2,