1

I just started with spring framework and i have a problem with my spring beans configurations. To load my static resources such as css, js, etc. i had to put the following line: <mvc:resources mapping=”/resources/**” location=”/resources/” /> in my spring bean configuration:

My problem is that if i put this line, for some reason all url's of my application are not mapped when i deploy my application. When i comment this line all the url's application are working just fine, but of course my static resources are not mapped.

I need some tips on how should i tackle this problem. Thank you !. Also this is all my spring-config.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: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-4.0.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-4.0.xsd 
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">


    <context:component-scan base-package="com.application" />
    <!-- Mapping the static resources -->
     <mvc:resources mapping="/resources/**" location="/resources/" />

    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/WEB-INF/views/" />
        <property name="suffix" value=".jsp" />
    </bean>

    <!-- Unimportant for my problem -->
    <!-- Bean used for login from userDao(repository) -->
    <bean id="customUserDetailsService" class="com.application.service.CustomUserDetailsService"></bean>

    <!-- Setup the userDao(repository) -->
    <bean id="userDao" class="com.application.model.UserDAO" />

    <!-- Declared datasource bean -->
    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost/licenta" />
        <property name="username" value="root" />
        <property name="password" value="" />
    </bean>

</beans>

1 Answer 1

1

You need to add <mvc:annotation-driven /> to your spring-config.xml

Check out this similar problem

Sign up to request clarification or add additional context in comments.

3 Comments

Yes, that was it!. Thank you very much, i will mark you're answer in a minute. Thank you again.
Oh, my bad again, i did my research but i missed that one :).
Don't worry! This question does seem to come up often but is it kind of hard to find exactly what you're looking for. If it's not too much trouble, you can mark the question as answered in order for future viewers to see it's the correct answer without having to read the comments. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.