user236997
user236997

Reputation: 21

Can't resolve location /'resources/

I'm trying to add css to my spring web app. According to guides proper way to do that is to add some code in spring.xml:

<mvc:annotation-driven />
    <mvc:resources mapping="/resources/**" location="/resources/" />

But i receive error: Can't resolve location /'resources/

spring.xml file:

<?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"
       xmlns:tx="http://www.springframework.org/schema/tx"
       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
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/tool
        http://www.springframework.org/schema/tool/spring-tool.xsd">

    <!-- Step 3: Add support for component scanning -->
    <context:component-scan base-package="com" />

    <!-- Step 4: Add support for conversion, formatting and validation support -->


    <!-- Step 5: Define Spring MVC view resolver -->
    <bean
            class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/view/" />
        <property name="suffix" value=".jsp" />
    </bean>

    <bean id="myDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://localhost:3306/hb_student_tracker?useUnicode=true&amp;useJDBCCompliantTimezoneShift=true&amp;useLegacyDatetimeCode=false&amp;serverTimezone=UTC"/>
        <property name="username" value="hbstudent"/>
        <property name="password" value="hbstudent"/>
    </bean>


    <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
        <property name="dataSource" ref="myDataSource"/>
        <property name="packagesToScan" value="com.entity"/>
        <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
                    <prop key="hibernate.show_sql">true</prop>
                </props>
        </property>
    </bean>

    <bean id="myTransactionalManager"
          class="org.springframework.orm.hibernate5.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>

  <tx:annotation-driven transaction-manager="myTransactionalManager"/>

    <mvc:annotation-driven />
    <mvc:resources mapping="/resources/**" location="/resources/" />

</beans>

Upvotes: 1

Views: 1057

Answers (1)

user236997
user236997

Reputation: 21

Finally, somehow i've found solution: That's how path to files look: web/resources/css/ Notice, that folder resources is a regular folder that's not marked as "Resource folder" spring.xml contains following:

 <mvc:resources mapping="/resources/**" location="/resources/"/>

Upvotes: 1

Related Questions