我挠挠脑袋。
我使用基于Spring 3.2 xml配置的应用程序,我升级到spring 4.X,理想情况下是4.3.7(这是为了简化操作,因为我实际上也在升级休眠等)。当我/如果我迁移到4.0.6(小于4.1)时,我设法复制了这个问题,一切正常。
我尝试了多个4.1.X和4.3.X,实际上我没有得到servlet的映射解析。
https://localhost:8443/oldApp/home
结果
2017-04-03 12:06:40,383 WARN {OLDAPP} [org.springframework.web.servlet.PageNotFound] - 在名称为&#39的DispatcherServlet中找不到带有URI [/ oldApp / home]的HTTP请求的映射;弹簧-MVC' 2017-04-03 12:06:40,383 WARN {OLDAPP} [org.springframework.web.servlet.PageNotFound] - 在DispatcherServlet中找不到带有URI [/ oldApp / 404]的HTTP请求的映射,名称为' spring- MVC'
基本上,它尝试转到/ home的映射但是失败,根据配置重定向到404,并且还失败了/ 404的映射。
的applicationContext-mvc.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<mvc:annotation-driven/>
<context:component-scan base-package="com.verification.migration.controller.*" />
<!-- Static resources -->
<!-- Handles HTTP GET requests for /resources/** by efficiently serving
up static resources in the ${webappRoot}/resources directory -->
<mvc:resources mapping="/resources/**" location="/resources/" order="0" />
<mvc:resources mapping="/favicon.ico" location="/favicon.ico" order="0" />
<mvc:resources mapping="/robots.txt" location="/robots.txt" order="0" />
<mvc:resources mapping="/css/**" location="/css/" order="0" />
<mvc:resources mapping="/js/libs/**" location="/js/libs/" order="0" />
<mvc:resources mapping="/img/**" location="/img/" order="0" />
<mvc:resources mapping="/img/flags/**" location="/img/flags/" order="0" />
<!-- Welcome page -->
<mvc:view-controller path="/" view-name="redirect:/home"/>
<!-- wrapper of org.springframework.web.multipart.commons.CommonsMultipartResolver -->
<bean id="multipartResolver" class="com.verification.migration.util.DropOversizeFilesMultipartResolver">
<!-- the maximum file size in bytes -->
<property name="maxUploadSize" value="500000000000000000"/>
<property name="maxInMemorySize">
<value> 50000000 </value>
</property>
</bean>
<!-- Message internalization by using a db -->
<bean id="messageSource" class="com.verification.migration.util.DatabaseMessageSource">
<property name="messageRepository" ref="messageRepository" />
</bean>
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
<!-- <property name="defaultLocale" value="en_UK"/> -->
</bean>
<mvc:interceptors>
<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="ln" />
</bean>
</mvc:interceptors>
<!-- THYMELEAF: Template Resolver for email templates -->
<bean id="emailTemplateResolver"
class="org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver">
<property name="prefix" value="templates/" />
<property name="templateMode" value="HTML" />
<property name="characterEncoding" value="UTF-8" />
<property name="checkExistence" value="true" />
<property name="order" value="1" />
</bean>
<!-- THYMELEAF: Template Resolver for webapp pages templates -->
<bean id="webTemplateResolver"
class="org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".html" />
<property name="templateMode" value="HTML" />
<property name="cacheable" value="false" />
<property name="characterEncoding" value="UTF-8" />
<property name="checkExistence" value="true" />
<property name="order" value="2" />
</bean>
<bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">
<property name="templateResolvers">
<set>
<ref bean="emailTemplateResolver" />
<ref bean="webTemplateResolver" />
</set>
</property>
<!-- These lines configure the dialects to use with Thymeleaf -->
<property name="dialects">
<set>
<bean class="org.thymeleaf.spring4.dialect.SpringStandardDialect"/>
</set>
<!-- Table4j additional dialect -->
</property>
<property name="additionalDialects">
<set>
<bean class="org.thymeleaf.extras.springsecurity3.dialect.SpringSecurityDialect"/>
</set>
</property>
</bean>
<bean id="viewResolver" class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
<property name="templateEngine" ref="templateEngine" />
<property name="contentType" value="text/html;charset=UTF-8" />
<property name="characterEncoding" value="UTF-8" />
</bean>
</beans>
而 web.xml 是
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
metadata-complete="true" version="3.0">
<display-name>OLDAPP</display-name>
<description></description>
<!-- Character encoding filter -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Spring-security filter -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Multipart Filter -->
<filter>
<filter-name>MultipartFilter</filter-name>
<filter-class>org.springframework.web.multipart.support.MultipartFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>MultipartFilter</filter-name>
<servlet-name>/*</servlet-name>
</filter-mapping>
<!-- CAS filter -->
<filter>
<filter-name>CAS Single Sign Out Filter</filter-name>
<filter-class>org.jasig.cas.client.session.SingleSignOutFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CAS Single Sign Out Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Session timemout Filter -->
<filter>
<filter-name>SessionTimeoutCookieFilter</filter-name>
<filter-class>com.verification.migration.filter.SessionTimeoutCookieFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>SessionTimeoutCookieFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Parameters for make autowire possible inside filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext.xml
</param-value>
</context-param>
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext*.xml</param-value>
</context-param>
<!-- If the environment variable -Dspring.profiles.active is not set the default profile is local -->
<context-param>
<param-name>spring.profiles.default</param-name>
<param-value>local</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Simple context initializer that log current envirnoment profile used
by the webapplication -->
<context-param>
<param-name>contextInitializerClasses</param-name>
<param-value>com.verification.migration.util.ContextProfileInitializer</param-value>
</context-param>
<listener>
<description>Servet Listener used to avoid ClassLoader Memory Leak</description>
<listener-class>com.verification.migration.util.DciContextListener</listener-class>
</listener>
<listener>
<listener-class>org.jasig.cas.client.session.SingleSignOutHttpSessionListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>spring-mvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-mvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<error-page>
<error-code>403</error-code>
<location>/403</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/404</location>
</error-page>
<error-page>
<error-code>405</error-code>
<location>/405</location>
</error-page>
<error-page>
<exception-type>org.springframework.web.bind.MissingServletRequestParameterException</exception-type>
<location>/404</location>
</error-page>
<error-page>
<exception-type>org.springframework.web.bind.ServletRequestBindingException</exception-type>
<location>/404</location>
</error-page>
<error-page>
<exception-type>org.springframework.web.multipart.support.MissingServletRequestPartException</exception-type>
<location>/404</location>
</error-page>
<error-page>
<error-code>400</error-code>
<location>/404</location>
</error-page>
<security-constraint>
<web-resource-collection>
<web-resource-name>Restricted methods</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>PUT</http-method>
<http-method>DELETE</http-method>
<http-method>TRACE</http-method>
<http-method>OPTIONS</http-method>
</web-resource-collection>
<auth-constraint/>
</security-constraint>
<session-config>
<session-timeout>10</session-timeout>
<cookie-config>
<http-only>true</http-only>
</cookie-config>
<tracking-mode>COOKIE</tracking-mode>
</session-config>
HomeController.java
package com.verification.migration.controller;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import javax.annotation.PostConstruct;
import javax.mail.MessagingException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jxl.write.WriteException;
import nl.captcha.Captcha;
import nl.captcha.servlet.CaptchaServletUtil;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.http.MediaType;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.validation.Errors;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.google.common.base.Optional;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.Lists;
import com.googlecode.flyway.core.Flyway;
@SessionAttributes({ "userLogged", "mpFields"})
@Controller
public class HomeController {
private static final Logger logger = LoggerFactory
.getLogger(HomeController.class);
@Value("${receipt.folder}")
private String RECEIPT_FOLDER;
@RequestMapping(value = { "/home", "/homeprivate" }, method = RequestMethod.GET)
public String entryPoint(Model model, Locale locale,
HttpServletRequest request, HttpServletResponse response,
SessionStatus sessionStatus) {
model.addAttribute("isHomepage", "true");
return "homepage";
}
}
因为这似乎适用于3.2.X(旧版本和依赖项)和4.0.6(我在这里发布的非常相同的文件,只有不同的maven依赖版本指向spring-core和spring MVC 4.0.X)就XML配置而言,我倾向于认为4.1必须改变一些东西,因为我使用java配置运行其他应用程序就好了4.3.7。 旧版本也使用了Thymeleaf2,我升级到了Thymeleaf3,但它并不是罪魁祸首,因为使用spring 4.0.6我设法让Thymeleaf2和Thymeleaf3完美运行应用程序。同样适用于hibernate版本的升级。
因此我将其确定为弹簧,例如从弹簧3.2.2升级 - >弹簧4.0.6(并且只在需要时修改,因为从spring3到spring4有一些依赖性切换)它工作 - &gt;弹簧4.1.9没有触及弹簧(核心,mvc等)以外的任何东西,调用的调度失败......
任何人都可以指出我在这里完全失踪了什么?
提前致谢。
答案 0 :(得分:0)
由于我没有收到关于这个主题的答案,我只会自己提出一个答案,这本身就是一种黑客攻击,但至少让我经历过......
我更改了applicationContext-mvc.xml以引用一个java配置文件,该配置文件又处理配置。 虽然这有效,但这只是确认在我的xml文件中有些东西没有正确完成,但是由于没有关于spring mvc xml配置文件的4.0.X到4.1.X中记录的“更改”,我会归咎于缺乏文件......
所以请注意,当从3.X或4.0.X切换到4.1.x时,您可能会遇到一些麻烦,我建议如果您无法确定哪些是完全错误的(就像我没有做到的那样) ,使用xml配置声明java配置的组件扫描(仅适用于mvc)来启动应用程序的mvc组件将使...
不是最美丽的东西,但这是我想出的唯一解决方案......