spring-boot jsp whitelabel error page问题解决
来源:互联网 发布:mysql数据库默认密码 编辑:程序博客网 时间:2024/05/17 08:16
spring-boot jsp whitelabel error page问题解决
spring-boot配置jsp,访问:http://127.0.0.1:8080,显示如下错误信息:
Whitelabel Error PageThis application has no explicit mapping for /error, so you are seeing this as a fallback.Tue Dec 12 13:04:58 CST 2017There was an unexpected error (type=Not Found, status=404)./WEB-INF/jsp/test1.jsp
打印Tomcat上下文指向目录:
public static void main(Stringp[] args){ ConfigurableApplicationContext context = SpringApplication.run(ApplicationMain.class, args); ServletContext context1 = context.getBean(ServletContext.class); URL url = context1.getResource("/"); System.out.prinltn("ContextRoot Path: {}", url.getFile());}Output:/C:/Users/ADMINI~1/AppData/Local/Temp/tomcat-docbase.2813863602259672077.8081/
说明Tomcat未能正确指向项目路径,打断点翻看源代码TomcatEmbeddedServletContainerFactory.java:
protected void prepareContext(Host host, ServletContextInitializer[] initializers) { // 准备容器上下文,获取可用文档根目录, // 一般为:src/main/webapp/;public;static // 如果未找到则创建临时目录,即上面打印的结果。 File docBase = getValidDocumentRoot(); docBase = (docBase != null ? docBase : createTempDir("tomcat-docbase")); final TomcatEmbeddedContext context = new TomcatEmbeddedContext(); context.setName(getContextPath()); context.setDisplayName(getDisplayName()); context.setPath(getContextPath()); context.setDocBase(docBase.getAbsolutePath()); context.addLifecycleListener(new FixContextListener()); context.setParentClassLoader( this.resourceLoader != null ? this.resourceLoader.getClassLoader() : ClassUtils.getDefaultClassLoader()); resetDefaultLocaleMapping(context); addLocaleMappings(context); try { context.setUseRelativeRedirects(false); } catch (NoSuchMethodError ex) { // Tomcat is < 8.0.30. Continue } SkipPatternJarScanner.apply(context, this.tldSkipPatterns); WebappLoader loader = new WebappLoader(context.getParentClassLoader()); loader.setLoaderClass(TomcatEmbeddedWebappClassLoader.class.getName()); loader.setDelegate(true); context.setLoader(loader); if (isRegisterDefaultServlet()) { addDefaultServlet(context); } if (shouldRegisterJspServlet()) { addJspServlet(context); addJasperInitializer(context); context.addLifecycleListener(new StoreMergedWebXmlListener()); } context.addLifecycleListener(new LifecycleListener() { @Override public void lifecycleEvent(LifecycleEvent event) { if (event.getType().equals(Lifecycle.CONFIGURE_START_EVENT)) { TomcatResources.get(context) .addResourceJars(getUrlsOfJarsWithMetaInfResources()); } } }); ServletContextInitializer[] initializersToUse = mergeInitializers(initializers); configureContext(context, initializersToUse); host.addChild(context); postProcessContext(context); }
一层一层分析spring-boot内嵌Tomcat容器源码后,可写个配置TomcatConfig.java解决此问题:
@Configurationpublic class TomcatConfig { @Bean public EmbeddedServletContainerFactory embeddedServletContainerFactory() { ConfigurableEmbeddedServletContainer factory = new TomcatEmbeddedServletContainerFactory(); // 请自行优化目录,可写配置参数 factory.setDocumentRoot(new File("D:\\Workspace\\IDEA\\spring-boot-web-demo\\src\\main\\webapp\\")); return (EmbeddedServletContainerFactory) factory; }}
Good Luck! :)
Contact Mail: xfoobar@163.com
阅读全文
0 0
- spring-boot jsp whitelabel error page问题解决
- Spring boot JSP访问页面显示Whitelabel Error Page
- spring boot: Whitelabel Error Page的解决方案
- spring boot: Whitelabel Error Page的解决方案
- spring boot: Whitelabel Error Page的解决方案
- Spring-Boot "Whitelabel Error Page" 解决方法总结
- Spring Boot报错Whitelabel Error Page
- Spring Boot报错Whitelabel Error Page
- Spring Boot自定义错误页面,Whitelabel Error Page处理方式
- Spring Boot框架Whitelabel Error Page SpEL注入漏洞分析
- Spring Boot自定义错误页面,Whitelabel Error Page处理方式
- Spring Boot 第一个HelloWorld程序 whitelabel Error Page
- 13.2 Spring Boot启动报错:Whitelabel Error Page
- 13.2 Spring Boot启动报错:Whitelabel Error Page
- 初学Spring Boot遇到Whitelabel Error Page的解决办法
- spring boot整合freemarker出现Whitelabel Error Page问题
- Spring Boot自定义错误页面,Whitelabel Error Page处理方式
- Spring boot启动提示Whitelabel Error Page 401 spring需要授权登录
- 手记_java反射原理_咕泡
- 线程安全
- 苹果HomePod难产背后:历时5年 差点被砍掉!
- 苹果无人车技术细节曝光:能识别被遮挡的行人
- 北京新能源车指标已排到2019 苹果屏下指纹专利曝光
- spring-boot jsp whitelabel error page问题解决
- 京东物流砸下10亿建基金 3年内全部油车变电车
- 专访爱普生中国市场负责人:磨剑六年 爱普生如何用墨仓式打印机征服市场
- qt交叉编译问题
- opencv(十四)--模板匹配
- IT伦理与道德之计算机病毒
- jQuery的$.fn与$.extend使用结合
- 《算法导论》排序算法
- B树、B-树、B+树、B*树