I have a spring boot project with packaging war stated in the pom file.
war
...
org.s
You can pass context parameters to the servlet context with a context.xml. Add this as context.xml next to your pom:
Then use the maven-war-plugin like this
org.apache.maven.plugins
maven-war-plugin
context.xml
true
Then use a profile to set the spring.profiles.active property. Spring actually will pick these up without config but somehow Spring Boot does not. For it to work in Spring Boot you can use something like this:
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);
}
}