【发布时间】:2019-06-09 12:58:32
【问题描述】:
我正在尝试使用 System.getproperty("spring.profiles.active") 在 JPA 实体侦听器中获取 Spring 活动配置文件。但它总是返回 Null 配置文件。但是我已经检查了服务器并且配置文件配置正确。
我尝试使用 Environment 获取 Spring 活动配置文件,但在侦听器中,我也无法 @Autowired Environment。
@PostUpdate
public void methodInvoked afterUpdate(Example example){
String activeProfile = System.getproperty("spring.profiles.active");
}
请指教!
【问题讨论】:
-
它不是系统属性,它是 Spring 环境的一部分。请改用
@Value或自动连接Environment:stackoverflow.com/questions/9267799/… -
@BackSlash,你是对的。但在 JPA EntityListener
@Value或Environment中不起作用。正如@Karol Dowbecki 提到的,我必须明确需要在我的 Listener 类中注入依赖项。
标签: java spring-boot jpa entitylisteners