Springboot发现注入service和mapper为null
在一次刚搭建项目结构,想看看自己的dao层是否有效,打算用测试类,测试一下,dao和service有没有用,发现,空指针,后来就试着打印相关mapper和service,发现为空!!!原来的代码:@SpringBootTestpublic class MybatisTest {@AutowiredDemoService demoService;@AutowiredDemoMapper demoMa
·
在一次刚搭建项目结构,想看看自己的dao层是否有效,打算用测试类,测试一下,dao和service有没有用,发现,空指针,后来就试着打印相关mapper和service,发现为空!!!
原来的代码:
@SpringBootTest
public class MybatisTest {
@Autowired
DemoService demoService;
@Autowired
DemoMapper demoMapper;
@Test
public void daoTEST(){
//demoService.getUser();
System.out.println(demoMapper);
System.out.println(demoService);
}
}
打印结果:
现在代码:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SxApplication.class)
public class MybatisTest {
@Autowired
DemoService demoService;
@Autowired
DemoMapper demoMapper;
@Test
public void daoTEST(){
//demoService.getUser();
System.out.println(demoMapper);
System.out.println(demoService);
}
}
结果 :
更多推荐
已为社区贡献1条内容
所有评论(0)