Java 静态方法注入service的问题

@Component
public class PosCommonUtils{

   @Resource
    private HotelService hotelService;

    private static PosCommonUtils posCommonUtils;

    @PostConstruct
    public void init() {
        posCommonUtils = this;
        posCommonUtils.hotelService= this.hotelService;
    }
  public static void getList(String code){
    posCommonUtils.hotelService.getHotelBaseInfo(code);
  }
}
//@PostConstruct把需要用的service加载到定义的静态内部对象中 先进行init()方法,在进行@Resource注入
posted @ 2021-07-16 16:43  寒水易兮萧萧风  阅读(496)  评论(0编辑  收藏  举报