5

I'm working on a project, which is developed using SpringBoot 1.4.3-RELEASE.

According to the company internal document, it requires us to define a in the WEB-INF/web.xml, per application. The example is below:

<resource-ref>
    <res-ref-name>connectivityConfiguration</res-ref-name>
    <res-type>com.hide-my-company-name.ConnectivityConfiguration</res-type>
</resource-ref>

And then use JNDI lookup to get a certain object. But I don't have WEB-INF/web.xml.

So instead of WEB-INF/web.xml, I define the resource in my local tomcat context.xml.

<Context>
    <Resource name="connectivityConfiguration" 
              type="com.hide-my-company-name.ConnectivityConfiguration" />
</Context>

It works. However, only in my local development environment. Because I'm not able to change the 'context.xml' or 'server.xml' after deployment.

Question: Is there any other approach to define the same Resource using SpringBoot? E.g. via. Java code, or via application.properties?

Gin
  • 91
  • 7

1 Answers1

0
@SpringBootApplication
public class WebApplication extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(WebApplication.class);
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(WebApplication.class, args);
    }

    @Bean
    public TomcatEmbeddedServletContainerFactory tomcatFactory() {
        return new TomcatEmbeddedServletContainerFactory() {

            @Override
            protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(Tomcat tomcat) {
                tomcat.enableNaming();
                return super.getTomcatEmbeddedServletContainer(tomcat);
            }

            @Override
            protected void postProcessContext(Context context) {
                ContextResource resource = new ContextResource();
                resource.setName("connectivityConfiguration");
                resource.setType("com.hide-my-company-name.ConnectivityConfiguration");
                context.getNamingResources().addResource(resource);
            }
        };

}
}
ASP
  • 91
  • 1
  • 5