2017-04-03 16 views
0

我在挠头。我有一个应用程序使用基于Spring 3.2 xml的配置,我升级到春季4.X,理想情况下4.3.7(这是为了简化事情,因为我实际上还升级休眠,等等)。当/如果我迁移到4.0.6(小于4.1),一切正常,我设法复制这个问题。Servlet调度程序在使用xml配置升级到spring 4.1时出现问题

我试着改为多个4.1.X和4.3.X,实际上我没有从servlet获得映射分辨率。

https://localhost:8443/oldApp/home

导致

2017年4月3日12:06:40383 WARN {OLDAPP} [org.springframework.web.servlet.PageNotFound] - 没有映射找到HTTP请求与URI [/oldApp/home]在DispatcherServlet中名称为'spring-mvc' 2017-04-03 12:06:40,383 WARN {OLDAPP} [org.springframework.web.servlet.PageNotFound] - 未找到具有URI的HTTP请求的映射[/oldApp/404],名称为'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依赖版本指向弹簧核心和弹簧MVC 4.0.X)我倾向于认为,就XML配置而言,4.1必须改变一些,因为我有其他应用程序在4.3.7使用java配置运行得很好.. 旧版本也使用Thymeleaf2和我升级到Thymeleaf3,但它不是罪魁祸首,因为使用Spring 4.0.6我设法使应用程序与Thymeleaf2和Thymeleaf3完美无缺地运行。同样适用于在hibernate版本中升级。因此,我通过从春天的春天3.2.2 - >春天4.0.6(如果需要修改,因为有一些从spring3到spring4的一些依赖关系开关)升级,指出它弹簧,它的工作原理 - >弹簧4.1.9除了弹簧(核心,mvc等)之外没有任何东西触发调用失败...

任何人都可以指出我在这里完全失踪了什么?

在此先感谢。

+0

作为解决方法我更改了applicationContext-mvc.xml以引用将处理mvc的java配置文件,并且它的工作原理.. 这只是证实在我的xml文件中存在某些操作可以正确完成。 但作为在4.0.X到4.0.X中没有记录关于spring mvc xml配置文件的“更改”,而不是责怪我,我将其归咎于缺乏文档.. 如果没有人提供替代方案,我将把这个答案作为答案,并将问题标记为已解决,但我会*更喜欢达成正确的解决方案,而不是“单向或双向”地进行工作。 – witchedwiz

回答

0

当我收到关于这个主题没有答案,我就产生了自己的答案,这是排序本身就是一个黑客,但至少让我经历..

我改变的applicationContext-MVC .xml引用一个java配置文件,然后处理配置.. 虽然这个工作,这只是确认有没有在我的xml文件中正确做的东西,但由于4.0.X到4.1.X有关春天mvc xml配置文件没有记录“更改”,我'因为没有文档,我们将其归咎于它..

所以要预先警告,当从3.X或4.0.X切换到4.1.x时,您可能会遇到一些麻烦,我建议如果您无法确定什么是错误的(就像我没有做到),使用xml配置声明java配置的组件扫描(仅用于mvc)来启动应用程序的mvc组件将使得做..

不是最美丽的东西,但这是我想出的唯一解决方案...

相关问题