關於Test類中不能使用Autowired注入bean的問題

在測試類中使用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");

    }
}
相關文章
相關標籤/搜索