Announcement Announcement Module
Collapse
No announcement yet.
<mvc:resources> not working for .js and .xml extensions Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • <mvc:resources> not working for .js and .xml extensions

    I have configured my web app to serve static resources (css,js etc) from a resources folder in web content.
    Attachment

    In my spring-servlet config file, I have set the set the mvc:resources tag to point to the resources folder
    Code:
     	<!-- the mvc resources tag does the magic -->
     <mvc:resources mapping="/resources/**" location="/resources/" />
     
    
        <!-- also add the following beans to get rid of some exceptions -->
     <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
     <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
    This setup works with no issues for '.css' or image(.gif,.jpg) files. But for '.js' or '.xml' extensions, it DOES NOT work. I tried to see if the spring documentation had any configurations to filter out specific extensions. If I change the extension of the javascript files to other than '.js' it works.

    Any suggestions/comments to where to look why spring is blocking specific extensions ?
    Attached Files

  • #2
    Adding the following to web.xml resolved this issue.

    <mime-mapping>
    <extension>xml</extension>
    <mime-type>text/xml</mime-type>
    </mime-mapping>
    <mime-mapping>
    <extension>js</extension>
    <mime-type>text/javascript</mime-type>
    </mime-mapping>

    Comment


    • #3
      That is strange.

      I have JS and CSS working correctly without doing this .

      I also don't have those beans.

      I suspect you have a conflict elsewhere.

      Perhaps try using the spring mvc-basic and adding your resources to that project and see if they work ?

      Comment


      • #4
        thanks stimpy.

        This issue is resolved. This was not a spring mvc issue, rather the web container (weblogic) issue. Weblogic needs explicit configuration of the mime-type for certain extensions.

        Comment


        • #5
          Hi guys,
          I am getting the same problem with Tomcat 6.0. I have used the same configuration as the first message mentions, i.e, my resources (the dojo folders) are placed in src/main/webapp.

          Also, I have defined
          <mvc:resources mapping="/resources/**" location="/resources/" />
          in my Spring config.

          Unfortunately, adding the mime settings in the web.xml did not resolve the issue.

          Any help is much appreciated.

          Cheers

          Comment


          • #6
            ravkrr

            I suspect your paths do not match.

            src/main/webapp may be where you put it but where does it end up when you build ?

            Your war or root folder should contain a meta-inf , a Web-in and a resources directory.

            try downloading the spring mvc-basic application and testing with that . Since that is working as configured it should help you determine whats wrong.

            Comment

            Working...
            X