2 Replies Latest reply: Sep 20, 2012 10:31 AM by Neil Doshi RSS

    Migrating from AS4 to AS7 - Problem loading view templates

    Neil Doshi Newbie

      I am migrating my spring mvc web app from AS4 to AS7.

      The application is having a hard time finding my view templates (we are using velocity templates for our view).

      This currently works fine in AS4 as is.

       

      The project structure is as follows:

      /

      /src

         /com

          (etc...)

      /WebContent

        /WEB-INF

          /velocity

           /login

            /login.vm

       

      Here is an excerpt from my spring config file:

       

       

       

       

       

      Stack Trace:

      org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource '/WEB-INF/velocity/login/login.vm'

                org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:483)

                org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:354)

                org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1400)

                org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1380)

                org.apache.velocity.app.VelocityEngine.getTemplate(VelocityEngine.java:401)

                org.springframework.web.servlet.view.velocity.VelocityView.getTemplate(VelocityView.java:535)

                org.springframework.web.servlet.view.velocity.VelocityView.getTemplate(VelocityView.java:520)

                org.springframework.web.servlet.view.velocity.VelocityView.checkTemplate(VelocityView.java:293)

                org.springframework.web.servlet.view.velocity.VelocityLayoutView.checkTemplate(VelocityLayoutView.java:122)

                org.springframework.web.servlet.view.velocity.VelocityView.initApplicationContext(VelocityView.java:258)

                org.springframework.context.support.ApplicationObjectSupport.initApplicationContext(ApplicationObjectSupport.java:119)

                org.springframework.web.context.support.WebApplicationObjectSupport.initApplicationContext(WebApplicationObjectSupport.java:69)

                org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.java:73)

                org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:70)

                org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:350)

                org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1331)

                org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:341)

                org.springframework.web.servlet.view.UrlBasedViewResolver.loadView(UrlBasedViewResolver.java:413)

                org.springframework.web.servlet.view.AbstractCachingViewResolver.createView(AbstractCachingViewResolver.java:159)

                org.springframework.web.servlet.view.UrlBasedViewResolver.createView(UrlBasedViewResolver.java:378)

                org.springframework.web.servlet.view.AbstractCachingViewResolver.resolveViewName(AbstractCachingViewResolver.java:78)

                org.springframework.web.servlet.DispatcherServlet.resolveViewName(DispatcherServlet.java:1215)

                org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1164)

                org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:902)

                org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)

                org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)

                org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)

                javax.servlet.http.HttpServlet.service(HttpServlet.java:734)

                javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

       

       

       

       

      I tried a few different options for the "prefix" property

      • /WEB-INF/velocity/
      • WEB-INF/velocity/
      • customerportal.war/WEB-INF/velocity/
      • com.odc.customerportal/WEB-INF/velocity/

       

       

       

      I am able to reorganize the location of the files in the built war file if necessary.

        • 1. Re: Migrating from AS4 to AS7 - Problem loading view templates
          Tomaz Cerar Master

          Can you upgrade spring to latest version (backward compatibilty is well taken care of)

          and upgrade velocity to some more recent version.

           

          if it still wont work we should check velocity code how it handled loading of resources.

           

           

          --

          tomaz

          • 2. Re: Migrating from AS4 to AS7 - Problem loading view templates
            Neil Doshi Newbie

            It turns out the problem was that in JBoss4 I was easily able to access anything under WEB-INF from the classloader.

            In JBoss7 I need to move the velocity folder from WEB-INF to WEB-INF/classes.

            I also had to update all the spring configuration and references to those files.

             

             

            Spring configuration file:

            <bean id="velocityConfigurer" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">

            <property name="resourceLoaderPath" value="/WEB-INF/classes/velocity" />

            <property name="configLocation" value="/WEB-INF/classes/velocity/velocity.properties"/>

            </bean>

             

             

            <bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver">

            <property name="prefix" value="" />

            <property name="suffix" value=".vm" />

            ...

            ...

            ...

            </bean>

             

             

            Velocity template files:

            Before:

            #set( $layout = "WEB-INF/velocity/layout/blank_layout.vm" )

             

            After:

            #set( $layout = "velocity/layout/blank_layout.vm" )

             

             

            Velocity.properties file:

            Before:

            velocimacro.library = vm_global_library.vm

             

            After:

            velocimacro.library = velocity/vm_global_library.vm