我可以为 Spring Boot 的嵌入式 tomcat 启用 tomcat 管理器应用程序吗? [英] Can I enable the tomcat manager app for Spring Boot's embedded tomcat?

查看:39
本文介绍了我可以为 Spring Boot 的嵌入式 tomcat 启用 tomcat 管理器应用程序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个研究项目,以确定我们可以在多大程度上使用 Spring Boot 配置嵌入式 Tomcat.我被要求调查的项目之一是关于我们是否仍然可以使用应用程序管理器.我没有一个具体的用例来说明为什么我们想要使用带有嵌入式 tomcat 的应用程序管理器,所以也许这使得这个问题无法回答:

I'm doing a research project to determine to what extent we can configure embedded Tomcat with Spring boot. One of the items I was asked to look into was with regard to whether we can still use the app manager. I don't have a specific use case for why we'd want to use an app manager with an embedded tomcat, so maybe that makes this question unanswerable:

Spring Boot 使用的嵌入式 tomcat 7 是否包含 tomcat 管理器应用程序,如果没有,如何添加/启用它?

Does the embedded tomcat 7 used by Spring Boot contain a tomcat manager app, and if not, what does it take to add/enable it?

推荐答案

Spring Boot 使用的嵌入式 tomcat 7 是否包含 tomcat manager app

Does the embedded tomcat 7 used by Spring Boot contain a tomcat manager app

不,它没有,而且我不确定尝试添加它是否有意义.

No, it doesn't and I'm not really sure that it makes sense to try to add it.

管理器应用程序的主要功能是允许您在不停止容器的情况下启动和停止单个应用程序,以及部署和取消部署单个应用程序.当您将 Spring Boot 与嵌入式 Tomcat 一起使用时,您应该将您的应用程序和容器视为单个实体,因此启动或停止应用程序以及启动和停止容器是一回事.

A primary function of the manager app is to allow you to start and stop individual applications without stopping the container and to deploy and undeploy individual applications. When you're using Spring Boot with embedded Tomcat you should consider your application and container as a single entity so starting or stopping your application and starting and stopping the container are one and the same thing.

管理器应用程序的第二个功能是提供对 OS 和 JVM 属性的访问,Spring Boot 的执行器已经为您做了这些.

A secondary function of the manager app is to provide access to OS and JVM properties, something that Spring Boot's actuator already does for you.

添加/启用它需要什么?

What does it take to add/enable it?

如果您选择不注意上述内容,则可以轻松添加管理器应用程序(尽管我不能保证一切都按预期工作 - 我将其留给(愚蠢的)读者作为练习):

If you choose not to heed the above, it's easy to add the manager app (although I can't promise that it all works as expected – I leave that as an exercise for the (foolhardy) reader):

@Bean
public EmbeddedServletContainerFactory servletContainer() {
    return new TomcatEmbeddedServletContainerFactory() {
        @Override
        protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(
                Tomcat tomcat) {
            tomcat.addUser("admin", "secret");
            tomcat.addRole("admin", "manager-gui");

            try {
                tomcat.addWebapp("/manager", "/path/to/manager/app");
            }
            catch (ServletException ex) {
                throw new IllegalStateException("Failed to add manager app", ex);
            }
            return super.getTomcatEmbeddedServletContainer(tomcat);
        }
    };
}

您还需要依赖 Jasper,因为管理器应用程序使用 JSP.假设您使用的是 Maven:

You'll also need a dependency on Jasper as the manager app uses JSPs. Assuming you're using Maven:

<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
</dependency>

这篇关于我可以为 Spring Boot 的嵌入式 tomcat 启用 tomcat 管理器应用程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆