我开始使用Spring Boot JSF . Spring文档说:

  • Spring将自动加载并提供/ static(或/ public或/ resources或/ META-INF / resources中的资源 . 这对我不起作用 .

  • 不建议使用“webapp”(src / main / webapp)文件夹 . 但对于我的静态内容,它似乎是唯一使用我的JSF静态页面的文件夹 .

Spring Boot static content .

我试过这些配置:

@Configuration
public class JSFServletConfigs  implements ServletContextInitializer// ,ServletContextAware
{

    @Override // ServletContext initiallization parameters
    public void onStartup(ServletContext servletContext) throws ServletException {

        servletContext.setInitParameter("facelets.DEVELOPMENT", "false");
        servletContext.setInitParameter("javax.faces.PROJECT_STAGE", "Development");
        servletContext.setInitParameter("javax.faces.DEFAULT_SUFFIX", ".xhtml");
        servletContext.setInitParameter("javax.faces.PARTIAL_STATE_SAVING_METHOD", "true");
        servletContext.setInitParameter("javax.faces.FACELETS_REFRESH_PERIOD", "-1");
    }

    @Bean // Registering the FacesServlet.
    public ServletRegistrationBean servletRegistrationBean() {
        FacesServlet servlet = new FacesServlet();
        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(servlet) {
            @Override
            public void onStartup(ServletContext servletContext) throws ServletException {
                FacesInitializer facesInitializer = new FacesInitializer();
                Set<Class<?>> clazz = new HashSet<Class<?>>();
                clazz.add(JSFServletConfigs.class);
                facesInitializer.onStartup(clazz, servletContext);
            }
        };
        servletRegistrationBean.addUrlMappings("*.xhtml", "*.jsf", "*.html");
        return servletRegistrationBean;
    }

    @Bean
    public InternalResourceViewResolver jsfViewResolving(){
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setViewClass(JstlView.class);
        viewResolver.setPrefix("/<sub-folder of any LOCATION>/");
        viewResolver.setSuffix(".xhtml");       
        return viewResolver;
    }
}

Servlet预配置:

@Configuration
@EnableWebMvc
public class DefaultServletConfigs extends WebMvcConfigurerAdapter {

    @Override // Enabling the default Servlet at path="/"
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

    private final String[] LOCATIONS = {"<All my possible locations>"};

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        if(!registry.hasMappingForPattern("/**")){
            registry.addResourceHandler("/**").addResourceLocations(LOCATIONS);
        }

        if(!registry.hasMappingForPattern("webjars")){
            registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
        }
    }
}

我的问题是:

我在这里错过了什么?

如何灵活地将我的资源放在上面的任何其他文件夹中(即“/ static”,“/ public”,“/ resources”,“/ META-INF / resources”) .