Spring Boot @Table annotation, catalog property fo

2019-07-17 02:25发布

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

Basically is not a problem

@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.

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.

2条回答
狗以群分
2楼-- · 2019-07-17 03:07

As far as I know you cannot edit annotation properties dynamically. Have a look at this post.

Maybe try having multiple abstract entities with it's own catalog name and do a switch based on an application.properties property to get the right one.

查看更多
该账号已被封号
3楼-- · 2019-07-17 03:18

Maybe such approach will work:

  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}")

查看更多
登录 后发表回答