Springboot无法从资源文件夹加载js文件 [英] Springboot unable to load js files from resources folder

查看:38
本文介绍了Springboot无法从资源文件夹加载js文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将项目上的项目上传到githttps://github.com/gitekiras/spring-boot-gradle-mvc

I have uploaded my project on the project to git https://github.com/gitekiras/spring-boot-gradle-mvc

我无法理解的是我无法从资源文件夹中加载 css 和 js.

What i am not able to get right is that i am not able to load the css and js from the resources folder.

当我把它放在 webapp 文件夹中时,我可以让每件事都正常工作,但根据教程,我应该把它们放在资源的静态文件夹中.

When i put it in webapp folder, i am able to get every thing working but according to the tutorials, i should put them in the static folder in resources.

但是当我这样做时,我无法在页面上加载 css 和 js.

but when i do so i am not able to load the css and js on page.

谁能告诉我我错过了什么?

Can any one say what i am missing ?

另外:当我在浏览器日志中看到时 - 它表明它正在尝试以 application/json 的形式查找 js 和 css 文件.我不确定我在这里做错了什么.

Also: when i see in browser logs - it shows that it is trying to find the js and css files as application/json. I am not sure what i have done wrong here.

推荐答案

您明确覆盖默认行为,添加您自己的@EnableWebMvc - 请参阅Spring MVC 自动配置.删除 @EnableWebMvc(以及 /resources/** 不需要的资源处理程序),它会起作用.

You explicitly overrode the default behavior by adding your own @EnableWebMvc - see Spring MVC auto-configuration. Remove the @EnableWebMvc (and also unneeded resource handler for /resources/**) and it will work.

这篇关于Springboot无法从资源文件夹加载js文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆