一.通过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);
}