Spring boot下@Autowired 注入为 NULL的问题

 @Autowired
 private SPIDao spiDao2;

发现为null,自己尝试在dao接口@Respority 和 @Compent 但是不行!!!!!!

Spring boot下@Autowired 注入为 NULL的问题_第1张图片
如下解决:

@Service
public class SPIServiceImpl2 implements SPIService{

    @Autowired
    private SPIDao spiDao2;

    private static SPIServiceImpl2 spiServiceimpl2;

    @PostConstruct
    public void init() {
        spiServiceimpl2 = this;
        spiServiceimpl2.spiDao2 = this.spiDao2;
    }


    @Override
    public Orgization findById(Integer orgId) {
        Orgization one = spiServiceimpl2.spiDao2.findOne(orgId);
        System.out.println("SPIServiceImpl2 的输出为:"+one);
        return one;
    }
}
public interface SPIDao extends CrudRepository {
}

你可能感兴趣的:(报错总结)