简体   繁体   English

CSS的背景图像未显示

[英]Background Image of CSS is not showing

I have written a Java WebApp with Vaadin 14.8.0 and SpringBoot.我用 Vaadin 14.8.0 和 SpringBoot 编写了一个 Java WebApp。 When I put the application in production mode and create a war file with the command "mvn clean package -Pproduction" and deploy it on my Wildfly, everything works normally.当我将应用程序置于生产模式并使用命令“mvn clean package -Pproduction”创建一个war文件并将其部署到我的Wildfly上时,一切正常。 My CSS files are read and also activated.我的 CSS 文件被读取并被激活。 However, the path I use in the css file for the background image is not found.但是,找不到我在 css 文件中用于背景图像的路径。

"background-image: url("/META-INF/resources/img/zac-bromell-QwrTnOlWAmI-unsplash.jpg");"

If I enter the path directly as url:如果我直接作为 url 输入路径:

"http://localhost:8080/planyoureplaylist-1.0-SNAPSHOT/META-INF/resources/img/zac-bromell-QwrTnOlWAmI-unsplash.jpg" 

I also get a 404 Not Found.我也得到一个 404 Not Found。

My css files are located in the root directory under ./frontend/styles .我的 css 文件位于./frontend/styles下的根目录中。 My image files can be found in src/main/resources/META-INF/resources/img/ .我的图像文件可以在src/main/resources/META-INF/resources/img/中找到。

I also looked at my WAR file with WINRAR.我还用 WINRAR 查看了我的 WAR 文件。 Since I notice that I find the image files in the directory WEB-INF\classes\META-INF\resources\img , but in the whole folder structure not my css files.因为我注意到我在WEB-INF\classes\META-INF\resources\img目录中找到了图像文件,但在整个文件夹结构中不是我的 css 文件。

To my surprise the background image was displayed normally when I started the application not yet via an external wildfly.令我惊讶的是,当我尚未通过外部野蝇启动应用程序时,背景图像正常显示。

In reference to the following link https://github.com/vaadin/flow/issues/11015 I understand that it is a bug of vaadin.参考以下链接https://github.com/vaadin/flow/issues/11015我了解这是 vaadin 的错误。 However, since I am on Vaadin 14.8.0 and the bug should be fixed with 14.6.2 I do not understand the problem.但是,由于我在 Vaadin 14.8.0 上并且应该使用 14.6.2 修复该错误,所以我不明白这个问题。

Gladly point out if something else is needed to solve the problem.很高兴指出是否需要其他方法来解决问题。

About help I would be very happy.关于帮助我会很高兴。 Thanks in advance提前致谢

The files in META-INF/resources are published in the server root so your META-INF/resources/img/zac-bromell-QwrTnOlWAmI-unsplash.jpg file is available at img/zac-bromell-QwrTnOlWAmI-unsplash.jpg inside your context root. META-INF/resources中的文件发布在服务器根目录中,因此您的META-INF/resources/img/zac-bromell-QwrTnOlWAmI-unsplash.jpg文件可在img/zac-bromell-QwrTnOlWAmI-unsplash.jpg中找到上下文根。 Your background image CSS should thus be "background-image: url("img/zac-bromell-QwrTnOlWAmI-unsplash.jpg");"因此,您的背景图像 CSS 应该是"background-image: url("img/zac-bromell-QwrTnOlWAmI-unsplash.jpg");"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM