在servlet中使用spring注解

@Autowired
IAgreementPayService agreementPayService;

/**
* 支付参数
*/
@Value("B{agreementPay.publicKey}")
private String publicKey;

/**
* 启动初始化上下文
*/
@Override
public void init() throws ServletException {
  super.init();
  ServletContext application = this.getServletContext();
  // 解决servlet用@Autowired自动注入service失败的问题
  SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this, application);
}

posted @ 2018-10-29 11:51  90后菜鸟-  阅读(1136)  评论(0编辑  收藏  举报