Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property defined using "server.context-parameters.*" doesn't work on Java EE server

We've generated a basic Spring Boot application to test some features.

I've prepared it to be deployed on an embedded server and on Java EE servers (Tomcat 7 and JBoss EAP 6.2) without applying any changes.

I've included server.context-parameters.* property on application.properties file.

If I deploy the application on an embedded server using java -jar or mvn spring-boot:run, it's working without problems. But, If I deploy the same application on Tomcat 7 or JBoss EAP 6.2, I'm not able to load the context-params correctly.

  • Which is the correct way to define context parameters on Spring Boot application deployed on Java EE container without use web.xml file?

You could see all debugging information related with this Spring Boot issue here

like image 819
jcgarcia Avatar asked Mar 13 '23 20:03

jcgarcia


1 Answers

Finally, I found the following solution thanks to Stéphane Nicoll

server.context-parameters.* only works for embedded servers, so to configure context-parameters on Java EE server is necessary to include a @Bean of type ServletContextInitializer like the following:

@Bean
public ServletContextInitializer contextInitializer() {
    return new ServletContextInitializer() {

        @Override
        public void onStartup(ServletContext servletContext)
                throws ServletException {
                servletContext.setInitParameter("dummy.type","on-context-parameters");
        }
    };
}
like image 76
jcgarcia Avatar answered Mar 16 '23 21:03

jcgarcia