I am trying to follow instructions and configure a prerender filter for Spring Boot but since there is no web.xml in Boot I need to do this with Java configurations.
Instructions for Spring applications with web.xml that I am trying to follow:
1: Add this line to your web.xml:
<filter>
<filter-name>prerender</filter-name>
<filter-class>com.github.greengerong.PreRenderSEOFilter</filter-class>
<init-param>
<param-name>prerenderToken</param-name>
<param-value>[get from prerender: http://ift.tt/1IoIqKS;
</init-param>
</filter>
<filter-mapping>
<filter-name>prerender</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
2: add dependency on your project pom:
<dependency>
<groupId>com.github.greengerong</groupId>
<artifactId>prerender-java</artifactId>
<version>1.6.4-SNAPSHOT</version>
</dependency>
What I did so far:
I added the dependency to the pom. I created a WebConfig class and instantiated the Bean:
@Configuration
public class WebConfig {
@Bean
public PreRenderSEOFilter PreRenderSEOFilter() {
PreRenderSEOFilter prerenderFilter = new PreRenderSEOFilter();
return prerenderFilter;
}
}
But I don't know how to configure it. The prerenderFilter
has a method init(FilterConfig filterConfig)
. But I'm not sure how to use it.
How do I configure this prerenderFilter?
You can set parameter using "FilterRegistrationBean().setInitParameters"
RépondreSupprimerregistration = new FilterRegistrationBean()
registration.setFilter(filter)
registration.setInitParameters(yourMap)