Spring Boot @Table批注,不同环境的目录属性 [英] Spring Boot @Table annotation, catalog property for different environments

查看:105
本文介绍了Spring Boot @Table批注,不同环境的目录属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Spring Boot与JPA一起使用来连接我的数据库. 我需要在实体的@Table注释中设置目录"属性.

I'm using Spring Boot with JPA to connect with my database. I need to set "catalog" property in @Table annotation on entities.

基本上不是问题

@MappedSuperclass
@NoArgsConstructor
@Table(catalog = "catalog_name")
public abstract class AbstractEntity

但是我必须找到简单的方法来更改目录值,因为在不同的环境下我具有不同的值.

but I have to find easy way to change the catalog value, cause that I have different values on different environments.

有人能以其他方式知道如何通过例如application.properties文件而不是硬编码字符串来更改此设置吗?

Could anyone know any other way how to change this by for example application.properties file instead of hardcoded string?

对于任何解决方案我都会感激不尽.

I would be grateful for any solution.

推荐答案

也许这种方法可行:

  1. 向Maven个人资料添加属性
  2. 将属性catalog.name添加到.properties文件
  3. 使用Spring @PropertySource批注加载属性文件
  4. 执行以下操作:

  1. Add property to maven profile
  2. Add property catalog.name to .properties file
  3. Load properties file with Spring @PropertySource annotation
  4. Do something like this:

@Table(catalog ="$ {catalog.name}")

@Table(catalog = "${catalog.name}")

这篇关于Spring Boot @Table批注,不同环境的目录属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆