Spring mvc 如何将Servlet类迁移到SpringMVC控制器类?
在我的项目中,我们必须从SpringFramework 3迁移到SpringFramework 4。在这个创建了servlet类的项目中,现在我必须迁移到SpringFramework4中,而不使用servlet类,并且必须迁移到相应的控制器类中。那么如何在Spring框架控制器中迁移servlet的init方法呢。这是我的密码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
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,而无需担心