SSM项目 单元测试中 注入bean 空指针异常

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

猜你喜欢

转载自www.cnblogs.com/Draymonder/p/10061015.html
今日推荐