user1755645
user1755645

Reputation: 945

Spring 3 Static Resource Mapping with Thymeleaf

I am having an issue mapping my static resources with Spring. I am getting a 404 error. My servlet code is as below

<?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-3.1.xsd
 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
 http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">

<context:component-scan base-package="web.controller" />

<!-- Enabling Spring MVC configuration through annotations -->
<mvc:annotation-driven />

<!-- Mapping Static Resources -->
<mvc:resources mapping="/css/**" location="/resources/css/" />
<mvc:resources mapping="/js/**" location="/resources/js/" />
<mvc:resources mapping="/images/**" location="/resources/images/" />
<mvc:resources mapping="/oldcss/**" location="/resources/oldResources/css/" />
<mvc:resources mapping="/oldjs/**" location="/resources/oldResources/js/" />
<mvc:resources mapping="/oldimages/**" location="/resources/oldResources/images/" />


<bean id="templateResolver"
    class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
    <property name="prefix" value="/WEB-INF/views/" />
    <property name="suffix" value=".html" />
    <property name="templateMode" value="HTML5" />
</bean>

<bean id="templateEngine" class="org.thymeleaf.spring3.SpringTemplateEngine">
    <property name="templateResolver" ref="templateResolver" />
</bean>

<bean class="org.thymeleaf.spring3.view.ThymeleafViewResolver">
    <property name="templateEngine" ref="templateEngine" />
    <property name="order" value="1" />
</bean>

I am referring to the static objects as --

<link rel="stylesheet" type="text/css" href="../oldcss/reset.css" th:href="@{/oldcss/reset.css}"/>
    <link rel="stylesheet" type="text/css" href="../oldcss/skeleton.css" th:href="@{/oldcss/skeleton.css}"/>
    <link rel="stylesheet" type="text/css" href="../oldcss/style.css" th:href="@{/oldcss/style.css}"/>
    <!-- Import JS -->
    <script src="../oldjs/jquery.min.js" th:src="@{/oldjs/jquery.min.js}"></script>
    <script src="../oldjs/responsiveslides.min.js" th:src="@{/oldjs/responsiveslides.min.js}"></script>

Can anyone help me find the possible issue? Thanks in advance :)

Upvotes: 2

Views: 5477

Answers (1)

user1755645
user1755645

Reputation: 945

Resolved this issue ... had to change the mapping in the servlet to

<mvc:resources mapping="/css/**" location="/WEB-INF/resources/css/" />

Upvotes: 2

Related Questions