快速注册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);
    }

 

posted @ 2022-03-31 09:49  骚哥  阅读(130)  评论(0编辑  收藏  举报