Set context-param in Spring Boot

The one that is set as below in web.xml.

web.xml


<context-param>
  <param-name>p-name</param-name>
  <param-value>-value</param-value>
</context-param>

Describe as follows in the property file.

application.yaml


server:
  context_parameters:
    p-name: hogehoge
    p-name2: foobar

The following is the code for checking the operation.

@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);
	}

}

However, according to How to set context-param in spring-boot, spring-boot 1.2 or later It's a function.

By the way, nothing happened when I put spring.profiles.active here. At least in the boot log it will be `No active profile set ...`.

application.yaml


server:
  context_parameters:
    spring.profiles.active: profile_ctx

Recommended Posts

Set context-param in Spring Boot
Spring Boot 2 multi-project in Gradle
Set cookies with Spring Boot
Major changes in Spring Boot 1.5
NoHttpResponseException in Spring Boot + WireMock
Specify spring.profiles.active via context-param of web.xml in Spring Boot
Spring Boot Hello World in Eclipse
Spring Boot application development in Eclipse
Write test code in Spring Boot
How to set Spring Boot + PostgreSQL
Implement REST API in Spring Boot
What is @Autowired in Spring boot?
Implement Spring Boot application in Gradle
Thymeleaf usage notes in Spring Boot
Launch (old) Spring Boot project in IntelliJ
Build Spring Boot + Docker image in Gradle
Static file access priority in Spring boot
Output Spring Boot log in json format
Local file download memorandum in Spring Boot
Challenge Spring Boot
Create Java Spring Boot project in IntelliJ
Loosen Thymeleaf syntax checking in Spring Boot
[Practice! ] Display Hello World in Spring Boot
Use DynamoDB query method in Spring Boot
Spring Boot Form
Spring Boot Memorandum
gae + spring boot
DI SessionScope Bean in Spring Boot 2 Filter
Change session timeout time in Spring Boot
SameSite cookie in Spring Boot (Spring Web MVC + Tomcat)
Test controller with Mock MVC in Spring Boot
Asynchronous processing with regular execution in Spring Boot
Run a Spring Boot project in VS Code
Output request and response log in Spring Boot
Use Servlet filter in Spring Boot [Spring Boot 1.x, 2.x compatible]
How to add a classpath in Spring Boot
Java tips-Create a Spring Boot project in Gradle
How to bind to property file in Spring Boot
Annotations used in Spring Boot task management tool
View the Gradle task in the Spring Boot project
Spring Boot --How to set session timeout time
Inject Logger in Spring
SPRING BOOT learning record 01
Spring Boot + Heroku Postgres
Spring boot memo writing (1)
Set CookieSpec in HttpClient 4.3
First Spring Boot (DI)
SPRING BOOT learning record 02
Spring Boot2 cheat sheet
Spring Boot exception handling
Spring Boot Servlet mapping
Spring boot development-development environment-
Spring Boot learning procedure
Use Interceptor in Spring
Learning Spring Boot [Beginning]
Microservices in Spring Cloud
Spring boot memo writing (2)
Spring Boot 2.2 Document Summary
[Spring Boot] DataSourceProperties $ DataSourceBeanCreationException
How to set environment variables in the properties file of Spring boot application
Spring Boot 2.3 Application Availability