Skip to content

Instantly share code, notes, and snippets.

@ArloL
Last active November 24, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArloL/232daa48bd00f3bcb25f to your computer and use it in GitHub Desktop.
Save ArloL/232daa48bd00f3bcb25f to your computer and use it in GitHub Desktop.
Demonstrate how to pass parameters to Spring Boot Application via Servlet Context Parameters
package com.example;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer {
private ServletContext servletContext;
@Override
protected SpringApplicationBuilder configure(
SpringApplicationBuilder builder) {
String activeProfiles =
servletContext.getInitParameter("spring.profiles.active");
if (activeProfiles != null) {
builder.profiles(activeProfiles.split(","));
}
return builder.sources(DemoApplication.class);
}
@Override
public void onStartup(ServletContext servletContext)
throws ServletException {
this.servletContext = servletContext;
super.onStartup(servletContext);
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment