spring-boot using multiple view resolvers from xml configuration not redirecting correctly -


i have legacy application using spring xml migrating spring-boot.

the application starts , authentication page, mapped in applicationcontext-login.xml. on login successful should load web-inf/client/home.jsp, but, instead, tries load /web-inf/auth/home.jsp , 404. in startup log see mapping paths. why conflicting on these redirects , can fix this? encounter issues because of multiple @importresource containing view resolvers?

extract security http configuration:

    <s:http use-expressions="true" entry-point-ref="delegatingauthenticationentrypoint">         <s:form-login login-page="/auth/login"                       login-processing-url="/auth/j_spring_security_check"                       authentication-failure-url="/auth/login-secure?loginfailed=true"                       default-target-url="/auth/defaultentry"/>         <s:logout logout-url="/auth/logout" logout-success-url="/auth/logout-success" delete-cookies="jsessionid"/>     </s:http> 

the controller points to:

    @requestmapping(value = "/defaultentry", method = requestmethod.get)     public string defaultentry() {         if (authentication.isauthenticated()) {               return "redirect:/client/home";         } else {             return "redirect:login";         }     } 

the application has multiple view resolvers configured in xml files:

  • classpath*:/springcontext/applicationcontext-login.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:context="http://www.springframework.org/schema/context"     xmlns:mvc="http://www.springframework.org/schema/mvc"     xsi:schemalocation="http://www.springframework.org/schema/beans                       http://www.springframework.org/schema/beans/spring-beans.xsd                       http://www.springframework.org/schema/context                       http://www.springframework.org/schema/context/spring-context.xsd                       http://www.springframework.org/schema/mvc                       http://www.springframework.org/schema/mvc/spring-mvc.xsd"     default-init-method="init"     default-destroy-method="destroy">    <import resource="applicationcontext-web-common.xml" />    <!-- static login resources -->   <mvc:resources mapping="/css/**" location="/web-inf/auth/css/"/>   <mvc:resources mapping="/assets/**" location="/web-inf/auth/assets/"/>   <mvc:resources mapping="/js/**" location="/web-inf/auth/js/"/>    <context:component-scan base-package="org.mycompany.auth" />    <!-- view resolver jsp -->   <bean id="loginviewresolver" class="org.springframework.web.servlet.view.internalresourceviewresolver">       <property name="viewclass" value="org.springframework.web.servlet.view.jstlview"/>       <property name="prefix" value="/web-inf/auth/"/>       <property name="suffix" value=".jsp"/>   </bean>    <bean id="localeresolver" class="org.springframework.web.servlet.i18n.cookielocaleresolver">       <property name="defaultlocale" value="en_us"/>   </bean> 

  • classpath*:/springcontext/applicationcontext-client.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:context="http://www.springframework.org/schema/context"       xmlns:mvc="http://www.springframework.org/schema/mvc"       xsi:schemalocation="http://www.springframework.org/schema/beans                         http://www.springframework.org/schema/beans/spring-beans.xsd                         http://www.springframework.org/schema/context                         http://www.springframework.org/schema/context/spring-context.xsd                         http://www.springframework.org/schema/mvc                         http://www.springframework.org/schema/mvc/spring-mvc.xsd"       default-init-method="init"       default-destroy-method="destroy">      <import resource="applicationcontext-web-common.xml" />      <context:component-scan base-package="org.mycompany.client" />      <!-- static resources -->     <mvc:resources mapping="/player/**" location="/web-inf/client/player/"/>     <mvc:resources mapping="/css/**" location="/web-inf/client/css/"/>     <mvc:resources mapping="/data/**" location="/web-inf/client/data/"/>     <mvc:resources mapping="/js/**" location="/web-inf/client/js/"/>     <mvc:resources mapping="/locales/**" location="/web-inf/client/locales/"/>     <mvc:resources mapping="/media/**" location="/web-inf/client/media/"/>     <mvc:resources mapping="/index.html" location="/web-inf/client/index.html"/>     <mvc:resources mapping="/test.html" location="/web-inf/client/test.html"/>     <mvc:resources mapping="/admin/**" location="/web-inf/client/admin/"/>     <mvc:resources mapping="/documentation/**" location="/web-inf/client/documentation/"/>       <bean id="clientviewresolver" class="org.springframework.web.servlet.view.internalresourceviewresolver">         <property name="viewclass" value="org.springframework.web.servlet.view.jstlview"/>         <property name="prefix" value="/web-inf/client/"/>         <property name="suffix" value=".jsp"/>     </bean>   </beans> 

there few others following same configuration pattern.

i loading resources in application.java

    @springbootapplication(exclude = {datasourceautoconfiguration.class, hibernatejpaautoconfiguration.class})     //@enablewebmvc     @componentscan({"org.mycompany"})     @importresource({"classpath*:/springcontext/applicationcontext-controllers.xml",             "classpath*:/springcontext/applicationcontext-rest.xml",             "classpath*:/springcontext/applicationcontext-login.xml",             "classpath*:/springcontext/applicationcontext-client.xml",             "classpath*:/springcontext/applicationcontext-admin.xml",             "classpath*:/springcontext/applicationcontext-logging.xml",             "classpath*:/springcontext/applicationcontext-web-common.xml"     })     public class application extends springbootservletinitializer {          public static void main(string[] args) throws unknownhostexception {             springapplication app = new springapplication(application.class);             applicationcontext ctx = app.run(args);             environment env = ctx.getenvironment();              logger.info(string.format("\n----------------------------------------------------------\n\t" +                             "application '%s' running! access urls:\n\t" +                             "local: \t\thttp://localhost:%s\n\t" +                             "external: \thttp://%s:%s\n----------------------------------------------------------",                     env.getproperty("spring.application.name"),                     env.getproperty("server.port"),                     inetaddress.getlocalhost().gethostaddress(),                     env.getproperty("server.port")));         }          @bean         public servletregistrationbean restdispatcher() {             servletregistrationbean registration = new servletregistrationbean(new dispatcherservlet(),                     "/rest/*", "/websocket/*");             registration.setname("rest-dispatcher");             registration.setloadonstartup(2);             map<string, string> params = new hashmap<>();             params.put("contextconfiglocation", "classpath*:springcontext/applicationcontext-rest.xml");             registration.setinitparameters(params);             return registration;         }          @bean         public servletregistrationbean authdispatcher() {             servletregistrationbean registration = new servletregistrationbean(new dispatcherservlet(), "/auth/*");             registration.setname("auth-dispatcher");             registration.setloadonstartup(2);             map<string, string> params = new hashmap<>();             params.put("contextconfiglocation", "classpath*:springcontext/applicationcontext-login.xml");             registration.setinitparameters(params);             return registration;         }          @bean         public servletregistrationbean clientdispatcher() {             servletregistrationbean registration = new servletregistrationbean(new dispatcherservlet(), "/client/*");             registration.setname("client-dispatcher");             registration.setloadonstartup(2);             map<string, string> params = new hashmap<>();             params.put("contextconfiglocation", "classpath*:springcontext/applicationcontext-client.xml");             registration.setinitparameters(params);             return registration;         }      //... other servlets registration, filters registration      } 

you returning redirect:/client/home login screen processed loginviewresolver:

<bean id="loginviewresolver" class="org.springframework.web.servlet.view.internalresourceviewresolver">       <property name="viewclass" value="org.springframework.web.servlet.view.jstlview"/>       <property name="prefix" value="/web-inf/auth/"/>       <property name="suffix" value=".jsp"/>   </bean> 

the clientviewresolver not invoked since there no order specified on view resolvers. can set order using order property.,


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -