SSM項目 單元測試中 注入bean 空指針異常


##特別

由於准備春招,所以希望各位看客方便的話,能去github上面幫我Star一下項目
https://github.com/Draymonders/Campus-Shop

 

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"})

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM