静态资源+web-inf+Spring启动

Static resources + web-inf + Spring Boot

我有一个 Spring 引导项目。项目结构是这样的:

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 or localhost:8080/static/css/mycss.css

访问我的 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.

我遵守标准

@SpringBootApplication
public class ConfigInitializer extends SpringBootServletInitializer{
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application){
        return application.sources(ConfigInitializer.class);
    }
    @Override
    public void onStartup(ServletContext container) throws ServletException {
        WebApplicationContext context = getContext();
        Dynamic registration = container.addServlet("dispatcher", new DispatcherServlet(context));
        registration.setLoadOnStartup(1);
        registration.addMapping("/*"); // required JBOSS EAP 6.2.0 GA
        super.onStartup(container);
    }
    private WebApplicationContext getContext() {
        AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
        context.setConfigLocation(ConfigInitializer.class.getName());
        return context;
    }
}

我可能做错了什么?