web.xmlで下みたいに設定するやつ。
web.xml
<context-param>
<param-name>p-name</param-name>
<param-value>-value</param-value>
</context-param>
プロパティファイルに以下のように記述する。
application.yaml
server:
context_parameters:
p-name: hogehoge
p-name2: foobar
以下は動作確認用のコード。
@RestController
@SpringBootApplication
public class App {
@Autowired
ServletContext ctx;
@RequestMapping("/home")
public String hoge() {
System.out.println(ctx.getInitParameter("p-name"));
System.out.println(ctx.getInitParameter("p-name2"));
return "hoge";
}
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
ただしHow to set context-param in spring-bootによるとspring-boot 1.2以降の機能とのこと。
ちなみに、ここにspring.profiles.active
を入れても何も起きなかった。少なくとも起動ログでは No active profile set ...
となる。
application.yaml
server:
context_parameters:
spring.profiles.active: profile_ctx