在测试类中使用AutoWired注解一直不能获取到Bean,调用方法时一直报空指针异常,我有在其余类中使用AutoWired试了下,发现可以生效。问题应该就是处在Test类中,后面找了半天终于找到问题了!!!测试
解决方法:spa
测试类上加以下注解:指针
@SpringBootTest
@RunWith(SpringRunner.class)
@SpringBootTest @RunWith(SpringRunner.class) public class AccountEmailServiceImplTest { @Autowired private AccountEmailService accountEmailService; @Test public void sendMail() throws Exception { accountEmailService.sendMail("xxx@163.com","hahhah","ddddd"); } }