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

 

posted @ 2018-12-03 21:25  Draymonder  阅读(1719)  评论(0)    收藏  举报