起因在开发中需要获取项目根目录,使用String contextPath = request.getSession().getServletContext().getRealPath("/");最终得到target目录,导致File始终报错。后百度到缘由在博主https://blog.youkuaiyun.com/u010870518/article/details/56498938中看到war模式和war exploded模式区别,便着手更换模式,由于半个新手,对IDEA不太熟悉,直接在exploded基础上创建war包(如下图)
接着直接在tomcat配置关联界面关联此war,运行就报错:
Artifact newzgX:war: Error during artifact deployment. See server log for details.
java.lang.IllegalStateException: Cannot set web app root system property when WAR file is not expanded
No Spring WebApplicationInitializer types detected on classpath
慌了神一直以为是不熟悉idea对web项目的其他配置,急匆匆百度的大多都是打包war,不是进行war模式开发。隔天静下心来来看清楚每个报错,关于配置war的目录结构,发现应该是war输出目录不对。

更换到tomcat安装目录的webapp下就正常了
本文分享了在IDEA中配置WAR模式的实战经验,详细讲述了从错误的exploded模式到正确WAR模式的过程,包括常见错误及解决方案,如Artifact:war:Error during artifact deployment和Cannot set web app root system property when WAR file is not expanded,并指出正确的WAR输出目录应为tomcat的webapp下。
744

被折叠的 条评论
为什么被折叠?



