Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法从spring MVC访问HTML文件_Html_Spring_Annotations - Fatal编程技术网

无法从spring MVC访问HTML文件

无法从spring MVC访问HTML文件,html,spring,annotations,Html,Spring,Annotations,我正在编写基本的SpringMVC应用程序,它没有基于注释的xml配置。我正在尝试访问html文件,如 “localhost:9090/help.html”但我得到错误 在名为“dispatcher”的DispatcherServlet中找不到URI为[/help.html]的HTTP请求的映射 这是我的配置 @EnableWebMvc @Configuration @ComponentScan({ "com.example.test" }) public class WebConf

我正在编写基本的SpringMVC应用程序,它没有基于注释的xml配置。我正在尝试访问html文件,如 “localhost:9090/help.html”但我得到错误
在名为“dispatcher”的DispatcherServlet中找不到URI为[/help.html]的HTTP请求的映射

这是我的配置

@EnableWebMvc  
@Configuration  
@ComponentScan({ "com.example.test" })  
public class WebConfig extends WebMvcConfigurationSupport {

    @Bean
    public InternalResourceViewResolver internalResourceViewResolver(){
        InternalResourceViewResolver internalResourceViewResolver = new InternalResourceViewResolver();
        internalResourceViewResolver.setViewClass(JstlView.class);
        internalResourceViewResolver.setPrefix("/jsp/");
        internalResourceViewResolver.setSuffix(".jsp");
        return internalResourceViewResolver;
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry){
        registry.addResourceHandler("/resources/**").addResourceLocations("/resources/*");
        registry.addResourceHandler("/**/*").addResourceLocations("/templates/*");
    }
}
我的html页面在里面
webapp->templates

我在这里尝试了很多问题,但没有一个有用,而且所有问题都与xml配置有关


有什么建议吗???

好的,我想出来了。这只是一个愚蠢的错误。在
addResourceLocations
中,我在最后删除了
*
,并解决了bingo问题

所以这是错误的

registry.addResourceHandler("/resources/**").addResourceLocations("/resources/*");
正确的形式是

registry.addResourceHandler("/resources/**").addResourceLocations("/resources");
现在我可以直接访问html页面,就像

localhost:8080/resources/help.html
甚至现在这也是可能的

localhost:8080/help.html
因为我添加了另一个资源处理程序作为
addResourceHandler(“/*\*/**”)