无法加载JavaScript文件,而同一目录中的其他JavaScript文件正确加载

时间:2019-07-13 12:15:22

标签: javascript spring-mvc spring-security kendo-ui thymeleaf

我正在使用Spring Boot 2.1.6.RELEASE,Thymeleaf 3,Spring Security

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.CacheControl;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

import java.util.Locale;
import java.util.concurrent.TimeUnit;

/**
 * Configuration for overall application.
 */
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class WebConfig extends WebMvcConfigurationSupport {

    @Bean
    public ViewResolver getViewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/templates/");
        resolver.setSuffix(".html");
        return resolver;
    }

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

}

header.html(胸腺模板文件)中

<script type="text/javascript" th:src="@{/js/kendo.messages.vi-VN.js}"><!--this file cannot load--></script>
<script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
<script type="text/javascript" th:src="@{/js/kendo.all.min.js}"></script>

3个JavaScript文件:/js/kendo.messages.vi-VN.js/js/jquery.min.js/js/kendo.all.min.js我放在同一目录中。

文件/js/jquery.min.js/js/kendo.all.min.js加载成功。文件/js/kendo.messages.vi-VN.js无法访问

enter image description here

在Google Chrome浏览器控制台上 enter image description here

在IDE中

enter image description here

在Firefox Web浏览器控制台上

enter image description here

https://github.com/donhuvy/kendo-ui-core/blob/master/src/cultures/kendo.culture.vi-VN.js之类的文件内容

如何解决?

0 个答案:

没有答案