Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring mvc 如何将Servlet类迁移到SpringMVC控制器类?_Spring Mvc - Fatal编程技术网

Spring mvc 如何将Servlet类迁移到SpringMVC控制器类?

Spring mvc 如何将Servlet类迁移到SpringMVC控制器类?,spring-mvc,Spring Mvc,在我的项目中,我们必须从SpringFramework 3迁移到SpringFramework 4。在这个创建了servlet类的项目中,现在我必须迁移到SpringFramework4中,而不使用servlet类,并且必须迁移到相应的控制器类中。那么如何在Spring框架控制器中迁移servlet的init方法呢。这是我的密码 public class ABCServlet extends HttpServlet { static WebApplicationContext ctx; p

在我的项目中,我们必须从SpringFramework 3迁移到SpringFramework 4。在这个创建了servlet类的项目中,现在我必须迁移到SpringFramework4中,而不使用servlet类,并且必须迁移到相应的控制器类中。那么如何在Spring框架控制器中迁移servlet的init方法呢。这是我的密码

public class ABCServlet extends HttpServlet {

static WebApplicationContext ctx;

 public void init(ServletConfig config) throws ServletException {
        super.init(config);
        if (ctx == null) {
            ServletContext servletContext = getServletContext();
            ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);
        }
    }
}
在代码片段中

public class ABCServlet extends HttpServlet {

static WebApplicationContext ctx;

public void init(ServletConfig config) throws ServletException {
        super.init(config);
        if (ctx == null) {
            ServletContext servletContext = getServletContext();
            ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);
        }
    }
}
我看不出任何商业逻辑

因此,您可以将Servlet移植到SpringFramework3,或者从SpringFramework3升级到SpringFramework4,而无需担心