简体   繁体   中英

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. data source configuration and others.

Normally i would add something ike

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

but how can i achieve that in 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):

@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. You can found the project application sample here .

And you can find the discussion here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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