Warm tip: This article is reproduced from serverfault.com, please click

java-如何在 jsp 文件中获取当前的 Spring 配置文件。

(java - How to get current Spring profile in jsp file.)

发布于 2013-01-29 12:16:03

我正在开发 Spring MVC 应用程序。在我的应用程序中,我有两个配置文件,测试和生产。当我部署我的应用程序来测试环境,生产环境中的生产时,测试被启用。

我需要在 jsp 文件中获取当前配置文件。是否有可能 ?我不想发送额外的变量来获取此信息,因为文件包含在许多其他文件中。谢谢

Questioner
Marco
Viewed
0
Neal Donnan 2013-01-29 20:47:30

你可以使用以下内容:

ServletContext sc = request.getSession().getServletContext();
WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(sc);
String[] profiles = applicationContext.getEnvironment().getActiveProfiles();