// 整合之前
public class Demo{

    @Test
    public void fun(){
        // 获取工厂,加载配置文件
        ApplicationContext ac = 
                new ClassPathXmlApplicationContext("applicationContext.xml");

        // 获取对象
        UserService us = (UserService)ac.getBean("userService");

        us.sayHello();
    }
}

// 整合步骤
// 要求: 必须先导入 JUnit4 的 jar包;
// 步骤一: 导入 spring-text.jar;
// 步骤二: 在具体的程序类上添加注解

    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration("classpath:applicationContext.xml")
    public class Demo{

        @Resource(name="userService")
        private UserService userService;

        @Test
        public void fun(){
            userService.sayHello();
        }
    }

参考资料

相关文章:

  • 2021-08-11
  • 2021-06-05
  • 2021-09-22
  • 2021-10-24
  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
  • 2022-12-23
猜你喜欢
  • 2021-11-08
  • 2022-02-14
  • 2021-10-07
  • 2021-10-20
  • 2019-09-26
  • 2022-12-23
  • 2021-04-20
相关资源
相似解决方案