springmvc采用了注解方式,利用ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
context.getBean("");怎么去获得到对应的实例?
springmvc单元测试异常
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答
- 田心王大可 2018-07-22 13:52关注
public class TestSpring { @Test public void TestUserService() throws Exception{ @SuppressWarnings("resource") ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml"); UserService us=(UserService) ac.getBean("userService"); User user=new User(); user.setAge(1); user.setUserName("zhangsan"); user.setPassword("123456"); user.setTrueName("张三"); us.add(user); } }
解决 无用评论 打赏 举报