JUnitテストを使用しました
それは次のように書かれています:
@Component
public class Test_SSM {
@Autowired
private UserService userService;
@Test
public void show() {
System.out.println(userService);
}
}
次に、testshowメソッドを呼び出します
出力がnull
このように変更するだけです。テストクラスの2行の注釈
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration( locations = "classpath:applicationContext.xml")
/*locations属性值 为 spring 配置文件路径*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration( locations = "classpath:applicationContext.xml")
public class Test_SSM {
@Autowired
private UserService userService;
@Test
public void show() {
System.out.println(userService);
}
}