问题
I was always wondering why no primefaces theme gets applied and could never fix it. Today I found out that when I add a Bean "ServletContextInitializer" to my Application with the same stuff like in the web.xml
it works. I read something that app.properties
maybe overrides the settings? I got a application.properties
but just for the database and jpa/hibernate.
Application:
@EnableAutoConfiguration
@ComponentScan({ "de.develop.telefonbuch" })
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public FilterRegistrationBean<RewriteFilter> rewriteFilter() {
FilterRegistrationBean<RewriteFilter> rwFilter = new FilterRegistrationBean<RewriteFilter>(new RewriteFilter());
rwFilter.setDispatcherTypes(
EnumSet.of(DispatcherType.FORWARD, DispatcherType.REQUEST, DispatcherType.ASYNC, DispatcherType.ERROR));
rwFilter.addUrlPatterns("/*");
return rwFilter;
}
@Bean
public ServletContextInitializer servletContextCustomizer() {
return new ServletContextInitializer() {
@Override
public void onStartup(ServletContext sc) throws ServletException {
sc.setInitParameter(Constants.ContextParams.THEME, "afternoon");
sc.setInitParameter(Constants.ContextParams.FONT_AWESOME, "false");
sc.setInitParameter(ProjectStage.PROJECT_STAGE_PARAM_NAME, ProjectStage.Development.name());
}
};
}
@Bean
public ServletRegistrationBean<FacesServlet> servletRegistrationBean() {
FacesServlet servlet = new FacesServlet();
return new ServletRegistrationBean<FacesServlet>(servlet, "*.jsf");
}
}
My web.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd" version="3.1">
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>afterdark</param-value>
</context-param>
<context-param>
<param-name>primefaces.FONT_AWESOME</param-name>
<param-value>false</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
</web-app>
来源:https://stackoverflow.com/questions/55064653/context-param-values-in-web-xml-get-ignored