Spring Boot @Table批注,不同环境的目录属性 [英] Spring Boot @Table annotation, catalog property for different environments
问题描述
我正在将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.
推荐答案
也许这种方法可行:
- 向Maven个人资料添加属性
- 将属性catalog.name添加到.properties文件
- 使用Spring @PropertySource批注加载属性文件
-
执行以下操作:
- Add property to maven profile
- Add property catalog.name to .properties file
- Load properties file with Spring @PropertySource annotation
Do something like this:
@Table(catalog ="$ {catalog.name}")
@Table(catalog = "${catalog.name}")
这篇关于Spring Boot @Table批注,不同环境的目录属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!