快速注册service服务
作者:互联网
一.通过SpringContextHolder的getBean来注册service服务
导入的包:
import com.bessky.platform.context.SpringContextHolder;
代码
ProductService productService = SpringContextHolder.getBean("productService", ProductService.class);
int count = productService.queryChildCategoryClicksCount(condition);
二.通过Servlet Context来注册Service服务
导入的包
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
代码
private FTPFileService ftpFileService; public void init() throws ServletException { ServletContext servletContext = this.getServletContext(); WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext); this.ftpFileService = ctx.getBean("ftpFileService", FTPFileService.class); }
标签:context,service,productService,getBean,ftpFileService,SpringContextHolder,注册,imp 来源: https://www.cnblogs.com/saoge/p/16080387.html