我刚刚开始使用 spring 框架,我的 spring bean 配置有问题。
要加载我的静态资源,例如 css、js 等,我必须添加以下行:
<mvc:resources mapping=”/resources/**” location=”/resources/” />
在我的 spring bean 配置中:
我的问题是,如果我放置此行,由于某种原因,当我部署应用程序时,我的应用程序的所有 url 都不会映射。当我评论这一行时,所有 url 的应用程序都工作正常,但当然我的静态资源没有映射。
我需要一些关于如何解决这个问题的提示。谢谢 !。 这也是我所有的 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>
最佳答案
您需要添加<mvc:annotation-driven />
到你的 spring-config.xml
查看this类似问题
关于java - Spring配置bean静态资源映射和url映射?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22646552/