All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yixan.base.web.servlet.InitServlet Maven / Gradle / Ivy

There is a newer version: 3.7.1
Show newest version
package com.yixan.base.web.servlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.yixan.base.common.svc.file.service.LocalFileService;

public class InitServlet extends HttpServlet {

    /** 版本序列号 **/
    private static final long serialVersionUID = -8452019304732100649L;

    @Override
    public void init() throws ServletException {

        ServletContext context = getServletConfig().getServletContext();

        String webRootPath = context.getRealPath("/");
        // String contextPath = context.getContextPath();

        // 为LocalFileService设置WebRootPath
        WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(context);
        try {
            LocalFileService fs = ctx.getBean(LocalFileService.class);
            if (fs != null) {
                fs.setWebRootPath(webRootPath);
            }
        } catch (NoSuchBeanDefinitionException ignore) {
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy