怎么在servlet里面获取spring通过注解方式注入的service bean

2024-11-30 13:14:22
推荐回答(1个)
回答1:

GamePackService gamePackService;

@Override
public void init() throws ServletException
{
super.init();
WebApplicationContext wac = WebApplicationContextUtils
.getRequiredWebApplicationContext(getServletContext());
gamePackService = (GamePackService) wac.getBean("gamePackService");
}、

在servlet init 方法中加入