测试方法一
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:spring/applicationContext-*.xml", "classpath:spring/springmvc.xml" }) public class WebMagicTest { @Autowired private Userservice userservice; @Test public void findUserTest() throws Exception { userservice.findById(1); } }
测试方法二
public class CommonTest { private ApplicationContext applicationContext; @Before public void setUp() throws Exception { applicationContext = new ClassPathXmlApplicationContext(new String[]{"spring/applicationContext-*.xml","spring/springmvc.xml"}); } @Test public void testBeans() throws Exception { String[] list = applicationContext.getBeanDefinitionNames(); for (String str : list) { System.out.println(str); } } }
原文地址:https://www.cnblogs.com/324sige/p/9013327.html
时间: 2024-10-26 17:29:45