SSM專案 單元測試中 注入bean 空指標異常
阿新 • • 發佈:2018-12-03
java.lang.NullPointerException
at com.cumt.service.ShopCategoryServiceTest.testGetShopCategoryList(ShopCategoryServiceTest.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
public class ShopCategoryServiceTest{ @Autowired private ShopCategoryService shopCategoryService; @Test public void testGetShopCategoryList() { if(shopCategoryService == null) { System.out.println("shopCategoryService is null"); } } }
卡在空指標異常 卡了一個小時 才發現 忘記載入
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({"classpath:spring/spring-dao.xml", "classpath:spring/spring-service.xml"})