我的springBoot应用resources目录下有个urlrewrite.xml的配置文件(urlrewrite的配置)。配置了拦截器
@Bean
public FilterRegistrationBean urlRewriteFilter() {
FilterRegistrationBean fitler = new FilterRegistrationBean();
fitler.setFilter(new UrlRewriteFilter());
fitler.setName("UrlRewriteFilter");
fitler.addInitParameter("confPath","urlrewrite.xml");
fitler.addInitParameter("logLevel", "info");
fitler.addUrlPatterns("/about/index.html", "/fund/*", "/news/*", "/poster/*", "/subject/*", "/myhb/*", "/custominfomgr/*", "/verify/*", "/myinfo/*", "/user/*", "/research/*", "/trust/*");
return fitler;
}
采用SpringBoot自己的@SpringBootApplication方式启动没问题。使用外部的tomcat启动时,就加载不到urlrewrite.xml。
下面是UrlRewriteFilter加载配置文件的源码:
private void loadUrlRewriterLocal() {
InputStream inputStream = context.getResourceAsStream(confPath);
// attempt to retrieve from location other than local WEB-INF
if ( inputStream == null ) {
inputStream = ClassLoader.getSystemResourceAsStream(confPath);
}
URL confUrl = null;
try {
confUrl = context.getResource(confPath);
} catch (MalformedURLException e) {
log.debug(e);
}
String confUrlStr = null;
if (confUrl != null) {
confUrlStr = confUrl.toString();
}
if (inputStream == null) {
log.error("unable to find urlrewrite conf file at " + confPath);
// set the writer back to null
if (urlRewriter != null) {
log.error("unloading existing conf");
urlRewriter = null;
}
} else {
Conf conf = new Conf(context, inputStream, confPath, confUrlStr, modRewriteStyleConf);
checkConf(conf);
}
}
使用Application方式启动时, ClassLoader.getSystemResourceAsStream(confPath)是会读取到的。第三方tomcat启动时inputStream就会为null。
有哪位大神碰到过类似问题?