intellij idea spring项目 新建文件夹里面的内容读取不出来?

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/skyejy/article/details/84504303

我在webapp下新建了一个文件夹fonts,可是却一直跑不出来预期的字体效果。一开始我以为是路径写错了,但其实并没有写错。

新建的fonts文件夹里的内容一直读不出来。

后来,在大佬的指点下,才知道是因为配置文件没有修改。

打开spring-web.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:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       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/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        ">
    <!-- 配置springMVC -->
    <!-- 1:开启springMVC注解模式 -->
    <!-- 简化配置:
         (1)自动注册DefaultAnnotationHandlerMapping,AnnotationMethodHandlerAdapter
         (2)提供一系列:数据绑定,数字和日期的format  @NumberFormat,@DataTimeFormat
        xml,json默认读写支持
     -->
    <mvc:annotation-driven/>

    <!-- 2:配置jsp显示ViewResolver -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>
    <!-- 3:扫描web相关的bean -->
    <context:component-scan base-package="com.musicplayer.controller" />
    <!--Add configuration  for static resource files access-->
    <mvc:resources mapping="/js/**" location="js/"/>
    <mvc:resources mapping="/images/**" location="images/"/>
    <mvc:resources mapping="/css/**" location="css/"/>
    <mvc:resources mapping="/songs/**" location="songs/"/>
    <mvc:resources mapping="/lyrics/**" location="lyrics/"/>
    <mvc:resources mapping="/imgmz/**" location="imgmz/"/>
    <mvc:resources mapping="/yq/**" location="yq/"/>
    <mvc:resources mapping="/jsp/**" location="WEB-INF/jsp/"/>
    <mvc:resources mapping="/fonts/**" location="fonts/"/>
</beans>

猜你喜欢

转载自blog.csdn.net/skyejy/article/details/84504303