Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.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 boot Spring引导服务器为映像提供404_Spring Boot_Spring Mvc_Spring Security - Fatal编程技术网

Spring boot Spring引导服务器为映像提供404

Spring boot Spring引导服务器为映像提供404,spring-boot,spring-mvc,spring-security,Spring Boot,Spring Mvc,Spring Security,我两天来一直在想这个问题。关于这个问题,我已经看过至少6篇stackoverflow帖子,没有任何建议有效。我的html中有一个带有.png图像的谷歌登录按钮。网页加载,但图像显示404响应代码。映像文件位于src/main/resources/webapp/WEB-INF/images/中。我省略了与这个问题无关的代码,以缩短帖子 @EnableWebMvc public class MvcConfig implements WebMvcConfigurer { @Override

我两天来一直在想这个问题。关于这个问题,我已经看过至少6篇stackoverflow帖子,没有任何建议有效。我的html中有一个带有.png图像的谷歌登录按钮。网页加载,但图像显示404响应代码。映像文件位于src/main/resources/webapp/WEB-INF/images/中。我省略了与这个问题无关的代码,以缩短帖子

@EnableWebMvc
public class MvcConfig implements WebMvcConfigurer {


    @Override
    public void configureDefaultServletHandling(final DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

    @Override
    public void addResourceHandlers(final ResourceHandlerRegistry registry) {
        // Register resource handler for CSS and JS
        registry.addResourceHandler("/resources/**").addResourceLocations("classpath:/static/")
                .setCacheControl(CacheControl.maxAge(2, TimeUnit.HOURS).cachePublic());

        // Register resource handler for images
        registry.addResourceHandler("/images/**").addResourceLocations("/WEB-INF/images/")
                .setCacheControl(CacheControl.maxAge(2, TimeUnit.HOURS).cachePublic());
    }
}
在html页面中:

<button onclick="window.location.href = '/spring-security-oauth-server/login/google';">Login with Google<img src="googleLogin.png"></button>
使用谷歌登录

请检查您的“网络”选项卡,并用请求的URL更新您的问题,好吗?我假设它是相对的请求的url是我相信它应该是
/images/googleLogin.png
我也试过了,但没有成功。我尝试将文件放置在各种建议的位置并更新MVCConfig,但无法使其正常运行
http://localhost:8081//images/googleLogin.png
工作。请检查您的“网络”选项卡,并用请求的URL更新您的问题,好吗?我假设它是相对的请求的url是我相信它应该是
/images/googleLogin.png
我也试过了,但没有成功。我尝试将文件放置在各种建议的位置并更新MVCConfig,但无法使其正常运行
http://localhost:8081//images/googleLogin.png
工作。让它工作,然后更改URL
<button onclick="window.location.href = '/spring-security-oauth-server/login/google';">Login with Google<img src="googleLogin.png"></button>