0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Spring Bootでcontext-paramを設定

Posted at

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
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?