zibi
zibi

Reputation: 3323

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?

Upvotes: 2

Views: 2585

Answers (2)

NullPointer
NullPointer

Reputation: 412

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.

Upvotes: 0

geoand
geoand

Reputation: 64049

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(.......);
            }
        });
        }
    }
}

Upvotes: 1

Related Questions