设置激活profile
原文链接
作为servlet参数
package com.mkyong.servlet3;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
public class MyWebInitializer extends
AbstractAnnotationConfigDispatcherServletInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
super.onStartup(servletContext);
servletContext.setInitParameter("spring.profiles.active", "live");
}
}
方式2
package com.mkyong.servlet3;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
public class MyWebInitializer extends
AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected WebApplicationContext createRootApplicationContext() {
WebApplicationContext context =
(WebApplicationContext)super.createRootApplicationContext();
((ConfigurableEnvironment)context.getEnvironment()).setActiveProfiles("live");
return context;
}
}