Spring boot - 在Tomcat根目录中部署war应用程序
我正在实现一个 Spring boot 应用程序,并且有以下要求:
1 - 生成的应用程序必须是一个 war
2 - 在 tomcat 根目录中部署为 war
3 - 我们不必在 tomcat 中配置任何内容
我们在开发环境中使用 spring boot 2 和 tomcat 9
我们可以通过 main 启动应用程序,默认情况下 spring boot strat 它在根上下文 root \根据要求,这是 spring boot 的标准行为,
而当我们在 tomcat 中部署应用程序时,我们无法让它以 root 身份启动。
我们已经知道解决方法,例如重命名最终的war ROOT.war,该应用程序将覆盖tomcat中使用\上下文根的默认根应用程序,但这不是一个优雅的解决方案,我们想了解什么是问题
默认情况下,如果你在 tomcat 中玩像战争这样的 Spring Boot 应用程序,它会使用战争名称作为上下文根:我的意思是例如 text.war 那么上下文根将是 \test
但是如果我们尝试修改属性 server.servlet.context-path 无论我们在其中添加什么
它可能是我们想要实现的空上下文根 server.servlet.context-path=\
或与战争名称不匹配的其他名称(例如 server.servlet.context-path=\test2 )应用程序未在 tomcat 中正确发布(404 资源不可用)
显然,如果战争名称和配置的 server.servlet.context-path 匹配所有工作正常,
我们也知道我们可以配置 server.xml 并强制应用程序 使用我们想要的上下文根:
我们无法理解的一点是 1 - 为什么当我们在 tomcat 中部署战争时,我们无法配置 server.servlet.context-path 因为如果配置的路径与应用程序可访问的战争名称不匹配 2 - Sameone 找到了一个不错的解决方案来自动将应用程序部署为上下文根
I'm implementing a Spring boot application and i have have this requirements:
1 - The generated application must be a war
2 - Deployed as a war in the tomcat root
3 - we don't have to configure anything in tomcat
we are using spring boot 2 and tomcat 9
in our development envrionment we can start the application by the main and as default the spring boot strat it in the root context root \ as requested, this is the standard behaviour of spring boot
instead when we deploy the application in tomcat we are not able to let it start as root.
We know already the work around like renaming the final war ROOT.war, that the application will overwrite the dafault root application in tomcat that has use the \ context root, but this is not an elegant solution, we would like to understand what is the problem
By default if you doplay a spring boot application like a war in tomcat it use the war name as context root : i mean for exampl text.war then the context root will be \test
but if we try to modify the property server.servlet.context-path whatever we put in it
it could be the empty context root that we would like to achieve server.servlet.context-path=\
or another name that doenst mathch with the war name (liek server.servlet.context-path=\test2 ) the application is not properly published in tomcat (404 resource not available)
clearly if instead the war name and the configured server.servlet.context-path match all working properly
we know also the we can configure the server.xml and force the application
to use the context root that we want:
The point that we are not able to understand is
1 - why when we deploy the war in tomcat we cannot configured the server.servlet.context-path becouse if the path configured doesn't match with the war name the app is to reachable
2 - sameone foud a decent solution to automatically deploy the app as context root
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论