@Autowired注入Spring Bean,则当前类必须也是Spring Bean才能调用它,不能用new xxx()来获得对象,这种方式获得的对象无法调用@Autowired注入的Bean. 1.类1,加入Spring Pool public class PersonServiceImpl implements PersonService{ public void save(){ System.out.println("This is save for test spring")
转载请注明来源:四个空格 » IntelliJ IDEA中Mapper接口通过@Autowired注入报错的正确解决方式: 环境 ideaIU-2018.3.4.win: 错误提示: Could not autowire. No beans of 'JwDsBaseinfoCaseMapper' type found. less... (Ctrl+F1) Inspection info:Checks autowiring problems in a bean class. 错误如下图: 解决办法
在测试类中使用AutoWired注解一直不能获取到Bean,调用方法时一直报空指针异常,我有在其他类中使用AutoWired试了下,发现能够生效.问题应该就是处在Test类中,后面找了半天终于找到问题了!!! 解决方法: 测试类上加如下注解: @SpringBootTest@RunWith(SpringRunner.class) @SpringBootTest @RunWith(SpringRunner.class) public class AccountEmailServiceImplTes