Table name configured with external properties file

前端 未结 2 1914
予麋鹿
予麋鹿 2020-12-05 21:26

I build a Spring-Boot application that accesses a Database and extracts data from it. Everything is working fine, but I want to configure the table names from an external .p

2条回答
  •  独厮守ぢ
    2020-12-05 21:50

    Spring boot solution: Create below class

    @Configuration
    public class CustomPhysicalNamingStrategy extends SpringPhysicalNamingStrategy{
    
    @Value("${table.name}")
    private String tableName;
    
    @Override
    public Identifier toPhysicalTableName(final Identifier identifier, final JdbcEnvironment jdbcEnv) {
        return Identifier.toIdentifier(tableName);
    }
    

    }

    Add below property to application.properties:

    spring.jpa.properties.hibernate.physical_naming_strategy=.CustomPhysicalNamingStrategy
    table.name=product
    

提交回复
热议问题