简体   繁体   English

Java Web应用程序。 春季启动。 找到图像

[英]Java Web Application. Spring Boot. Locating Images

I've recently solved a problem of locating images in this community. 我最近解决了在这个社区中定位图像的问题。 You can look here . 你可以看看这里

However, one answer said: 但是,一个答案说:

Your app is a Spring Boot app. 您的应用是Spring Boot应用。 I think that you can also try to use the facilities provided by Spring Boot for serving static content. 我认为你也可以尝试使用Spring Boot提供的工具来提供静态内容。 Anyway, you are doing it right now because you are using webjars for css and js libs!!! 无论如何,你现在正在做,因为你正在使用webjars for css和js libs! Be consistent with the tech that you are using. 与您正在使用的技术保持一致。

This means, it's recommendable to locate the images files in /src/main/resources and not in /src/main/webapp . 这意味着,建议在/src/main/resources找到图像文件,而不是在/src/main/webapp

How could i use the facilites that Spring Boot provides me? 我怎么能使用Spring Boot为我提供的设施?

Thanks 谢谢

Spring Boot automatically configures production-ready settings and adds beans to your Spring project based on some dependencies that are declared in your maven/gradle build file. Spring Boot自动配置生产就绪设置,并根据maven / gradle构建文件中声明的一些依赖项向Spring项目添加bean。 As long as you follow the conventions, then you do not have to do so much configuration -- "convention over configuration" . 只要遵循惯例,那么您就不必进行如此多的配置 - “约定优于配置” For example, one convention is to load your images and static files in the resource classpath. 例如,一种约定是在资源类路径中加载图像和静态文件。 Refer to the documentation: http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/ 请参阅文档: http//docs.spring.io/spring-boot/docs/current/reference/htmlsingle/

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

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