简体   繁体   English

在Spring Boot中指定Tomcat'Resource's

[英]Specify Tomcat 'Resource's in Spring boot

I'm trying to run an application on spring boot, but to do that I need to add some resources to tomcat, eg. 我正在尝试在Spring Boot上运行应用程序,但是为此,我需要向tomcat添加一些资源。 data source configuration and others. 数据源配置等。

Normally i would add something ike 通常我会加一些东西

<Resources name="..." ....>

but how can i achieve that in spring boot? 但是我怎样才能在Spring Boot中实现呢?

I think the following would work for you (I have successfully used a similar approach to customize some other aspect of embedded tomcat): 我认为以下内容对您有用(我已经成功使用了类似的方法来自定义嵌入式tomcat的其他方面):

@Configuration
public class TomcatConfig implements EmbeddedServletContainerCustomizer {
    @Override
    public void customize(ConfigurableEmbeddedServletContainer container) {
        if(container instanceof TomcatEmbeddedServletContainerFactory) {
            TomcatEmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory = (TomcatEmbeddedServletContainerFactory) container;
            tomcatEmbeddedServletContainerFactory.addContextCustomizers(new TomcatConnectorCustomizer() {
            @Override
            public void customize(Connector connector) {
                connector.setNamingResources(.......);
            }
        });
        }
    }
}

There's a sample project in github that provides for resolving customizing Tomcat /setting resource property and they use datasource config as example. github中有一个示例项目,用于解决自定义Tomcat / setting资源属性的问题,并且它们使用datasource config作为示例。 You can found the project application sample here . 您可以在此处找到项目应用程序示例。

And you can find the discussion here . 您可以在这里找到讨论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM