多数据库设置中未使用的属性

出于监管和安全原因,我不得不将 Spring boot 应用程序的逻辑拆分为两个工具:一个用于管理有限数量的表,另一个用于“真实”用户应用程序。因此,我在服务器版本 5.7 上有两个 MySQL 数据库实例。虽然用户工具只访问一个包含几十个表的数据库,但管理工具需要访问两个数据库中的实体。


这些工具都基于 JavaFX 和 Spring Boot。由于这种架构设置,我有三个 maven 包:一个用于管理工具和所有与管理相关的实体、服务等,一个用于用户工具和所有相关实体、服务等。仅与此用户工具相关,第三个与这两个工具共享的所有实体。


当我运行用户工具时,它会在共享数据库中生成表,并根据其 application.properties 文件中的配置使用休眠改进命名策略。因此,列在适当的地方有一个下划线。


首先,管理工具根本不会使用 spring.jpa.hibernate.ddl-auto 创建任何数据库表,但我必须使用 spring.jpa.generate-ddl。


现在,当我运行管理工具时,我希望它只在管理数据库中创建表,因为这个数据源被注释为@Primary。但它也会在用户数据库中创建混合大小写的列。因此,我在用户数据库中有名为“email_address”和“emailAddress”的列。


我想知道我的方法是否使用了任何属性?任何想法如何正确地做到这一点?


请找到以下一些来源..


application.properties :


# Employee database

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

spring.datasource.jdbcUrl=jdbc:mysql://127.0.0.1/agiletunesdb?useSSL=false&serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&characterSetResults=utf-8

spring.datasource.username=YYY

spring.datasource.password=XXXXXX


# Account database

security.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

security.datasource.jdbcUrl=jdbc:mysql://127.0.0.1/authenticationdb?useSSL=false&serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&characterSetResults=utf-8

security.datasource.username=YYY

security.datasource.password=XXXXXX


# create db schema, values are none, validate, update, create, and create-drop. 

#spring.jpa.hibernate.ddl-auto=create

spring.jpa.hibernate.ddl-auto=update

#spring.jpa.hibernate.ddl-auto=none

spring.jpa.generate-ddl=true


# Naming strategy

spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy



# The SQL dialect makes Hibernate generate better SQL for the chosen database

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect


江户川乱折腾
浏览 124回答 1
1回答

蝴蝶刀刀

诀窍是使用具有@PropertySources({ @PropertySource("classpath:application.properties") })注解。然后,在创建 LocalContainerEntityManagerFactoryBean 的方法中,您可以拉取和设置在 application.properties 文件中定义的值properties.put("spring.jpa.hibernate.naming.physical-strategy", env.getProperty("spring.jpa.hibernate.naming.physical-strategy"));
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java