使用Java
主方法加载SpringContext
。 Annatation
无法获得该bean。
Java方法代码:
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"spring-mybatis.xml"});
context.start();
UserMapper userMapper = (UserMapper)context.getBean("userMapper");
System.out.println("userMapper----->:" + userMapper); //this line can get the bean,and print the bean's Memory Address
while(true){
Thread.sleep(1000);
}
但是当我使用Annatation
获取bean时,无法获取它,返回NULL
java代码:
@Resource
private UserMapper userMapper;