Javascript 弹簧靴-为什么可以';我的应用程序找不到静态资源吗?

Javascript 弹簧靴-为什么可以';我的应用程序找不到静态资源吗?,javascript,java,css,spring,spring-boot,Javascript,Java,Css,Spring,Spring Boot,我正在试一试Spring Boot,无法访问CSS、图像和JS文件 我有一个@springboot应用程序类: @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } 我的application.properties文件读取: spr

我正在试一试Spring Boot,无法访问CSS、图像和JS文件

我有一个@springboot应用程序类:

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
我的
application.properties
文件读取:

spring.datasource.url=jdbc:mysql://localhost:3306/<schema>?autoReconnect=true&useSSL=false
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.name=<sql-databasename>
spring.datasource.username=<sql-username>
spring.datasource.password=<sql-password>
#spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.database=MYSQL
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
spring.jpa.show-sql=false 
spring.jpa.hibernate.ddl-auto=update

# EMBEDDED SERVER CONFIGURATION (ServerProperties)
server.context-path=/<application-name>
server.display-name=<application-name>
server.port=8080
server.session.cookie.max-age=3600

# SPRING MVC (WebMvcProperties)
spring.mvc.favicon.enabled=true
spring.mvc.date-format=dd/MM/yyyy
spring.mvc.locale=pt_BR
spring.mvc.locale-resolver=accept-header
spring.mvc.servlet.load-on-startup=-1
spring.mvc.static-path-pattern=/**

# SPRING RESOURCES HANDLING (ResourceProperties)
spring.resources.add-mappings=true
spring.resources.cache-period=1
spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/**,classpath:/public/**

# THYMELEAF (ThymeleafAutoConfiguration)
spring.thymeleaf.cache=true
spring.thymeleaf.check-template-location=true
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
静态资源位于此处:

src/main/resources
    static
        css/
        img/
        js/
但是,当我试图访问任何静态资源时,比如,比如,在下面的浏览器调用中:

http://localhost:8080/.


我做错了什么以及如何让它工作?

从配置中删除
spring.resources.static locations
,除非您想更改它,否则默认情况下会包含
/static/

http路径中包括
静态
目录中的资源。
引用资源时,不包括
静态


文件
src/main/resources/static/css/bootstrap.min.css
应该在
http://localhost:8080/appname/css/bootstrap.min.css

从配置中删除
spring.resources.static locations
,除非您想更改它,否则默认情况下会包含
/static/

http路径中包括
静态
目录中的资源。
引用资源时,不包括
静态


文件
src/main/resources/static/css/bootstrap.min.css
应该在
http://localhost:8080/appname/css/bootstrap.min.css

静态文件夹直接映射到根URL,因此您将通过根URL+相对于静态文件夹fe的路径访问这些文件


localhost:8080/css/style.css

静态文件夹直接映射到根URL,因此您将通过根URL+相对于静态文件夹的路径访问这些文件

localhost:8080/css/style.css

src/main/resources
    static
        css/
        img/
        js/