I'm trying to use Tuckey
as urlRewrite in my spring boot project but i get error below registering Tuckey
filter:
org.tuckey.web.filters.urlrewrite.UrlRewriteFilter ERROR: unable to find urlrewrite conf file at `urlrewrite.xml` even i have `urlrewrite.xml` file under resources.
I register Tucky filter like below in my Configuration class
:
@Bean
public FilterRegistrationBean urlRewriteFilterRegistration() throws IOException {
log.info("UrlRewriteFilter registered!");
FilterRegistrationBean registration = new FilterRegistrationBean();
registration.setFilter(new UrlRewriteFilter());
registration.setName("UrlRewriteFilter");
List<String> urlPatterns = new ArrayList<>();
urlPatterns.add("/urlmap");
registration.setUrlPatterns(urlPatterns);
registration.getInitParameters().put("confPath","/urlrewrite.xml");
return registration;
}
Even i used to register Filter like below:
FilterRegistration.Dynamic urlRewriteFilter = servletContext.addFilter("urlRewriteFilter", new UrlRewriteFilter());
urlRewriteFilter.setInitParameter("confPath", "urlrewrite.xml");
urlRewriteFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, "/*");
it was working in none boot version! what is wrong with my configuration.
Had the same issue recently. Found this post with an answer: Spring boot cannot find urlrewrite.xml inside jar file
TL;DR: Created a class extending UrlRewriteFilter and overwrote the loadUrlRewriterMethod to allow loading a the configuration as a org.springframework.core.io.Resource
Please adapt to your needs:
and in the application class: