我有一个 Spring Boot 元素。元素结构是这样的:
src
|- main
|-java
|-demo
|-resources
|-static
|-css/mycss.css
当我在此基础上运行 Maven 构建时,我的 css 被打包成这样:
web-inf
|-classes
|-demo
|-static
|-css/mycss.css
我的问题是为什么它在“web-inf/classes”文件夹中打包静态资源,我无法通过 localhost:8080/css/mycss.css 或 localhost:8080/static/访问我的 CSS css/mycss.css
我的 pom.xml 是:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
最佳答案
src/main/resources 是 maven 中的默认资源文件夹,因此默认情况下,您放置在这里的任何配置都将位于类路径中,因此它将被放入 WEB-INF/classes 中。
关于java - 静态资源+web-inf+Spring Boot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28074784/