Spring资源处理:未找到

时间:2017-01-09 16:58:16

标签: spring spring-mvc spring-boot

我有 WEB-INF 文件夹,如下所示: enter image description here

在我的 webconfig.java

<?
$optarray  = explode("<br>", $getreq);

foreach($optarray as $optval){ ?>
<option><?= echo $optval; ?></option>
<? } ?>

在我看来我正在调用这样的资源[在' index.html ']中:

@Bean
public InternalResourceViewResolver internalResourceViewResolver() {

    InternalResourceViewResolver resolver = new InternalResourceViewResolver();
    resolver.setPrefix("/WEB-INF/views/");
    resolver.setSuffix(".html");

    return resolver;
}



@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {

    registry.addResourceHandler("/resources/**")
    .addResourceLocations("/WEB-INF/resources/");

}

但是资源没有加载,我得到 <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/lib/angular-toastr.css" >

我正在使用我的控制器访问我的索引页面:

Failed to load resource: the server responded with a status of 404 (Not Found)

索引页网址为:@RequestMapping("/myShellPage") public String ShellPage() { return "index"; }

产生错误的资源网址为:http://localhost:8080/gestionprojet/transtu/myShellPage?#/

任何帮助将不胜感激。谢谢

1 个答案:

答案 0 :(得分:0)

试试这个应该有效

@Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry
          .addResourceHandler("/resources/**")
          .addResourceLocations("(/resources/");    
    }

静态资源

<link href="<c:url value="/resources/lib/angular-toastr.css" />" rel="stylesheet">