My Spring Boot application runs with 3 configurations:
Simply add this class which allows to set global variables for views:
@ControllerAdvice
public class BuildPropertiesController {
@Autowired
private Environment env;
@ModelAttribute("isProd")
public boolean isProd() {
return Arrays.asList(env.getActiveProfiles()).contains("production");
}
}
And then use ${isProd}
variable in your thymeleaf file:
This is the production profile
Or you can set active profile name as a global variable:
@ControllerAdvice
public class BuildPropertiesController {
@Autowired
private Environment env;
@ModelAttribute("profile")
public String activeProfile() {
return env.getActiveProfiles()[0];
}
}
And then use ${profile}
variable in your thymeleaf file (if you have one active profile):
This is the profile