出于監(jiān)管和安全原因,我不得不將 Spring boot 應用程序的邏輯拆分為兩個工具:一個用于管理有限數量的表,另一個用于“真實”用戶應用程序。因此,我在服務器版本 5.7 上有兩個 MySQL 數據庫實例。雖然用戶工具只訪問一個包含幾十個表的數據庫,但管理工具需要訪問兩個數據庫中的實體。這些工具都基于 JavaFX 和 Spring Boot。由于這種架構設置,我有三個 maven 包:一個用于管理工具和所有與管理相關的實體、服務等,一個用于用戶工具和所有相關實體、服務等。僅與此用戶工具相關,第三個與這兩個工具共享的所有實體。當我運行用戶工具時,它會在共享數據庫中生成表,并根據其 application.properties 文件中的配置使用休眠改進命名策略。因此,列在適當的地方有一個下劃線。首先,管理工具根本不會使用 spring.jpa.hibernate.ddl-auto 創(chuàng)建任何數據庫表,但我必須使用 spring.jpa.generate-ddl?,F在,當我運行管理工具時,我希望它只在管理數據庫中創(chuàng)建表,因為這個數據源被注釋為@Primary。但它也會在用戶數據庫中創(chuàng)建混合大小寫的列。因此,我在用戶數據庫中有名為“email_address”和“emailAddress”的列。我想知道我的方法是否使用了任何屬性?任何想法如何正確地做到這一點?請找到以下一些來源..application.properties :# Employee databasespring.datasource.driver-class-name=com.mysql.cj.jdbc.Driverspring.datasource.jdbcUrl=jdbc:mysql://127.0.0.1/agiletunesdb?useSSL=false&serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&characterSetResults=utf-8spring.datasource.username=YYYspring.datasource.password=XXXXXX# Account databasesecurity.datasource.driver-class-name=com.mysql.cj.jdbc.Driversecurity.datasource.jdbcUrl=jdbc:mysql://127.0.0.1/authenticationdb?useSSL=false&serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&characterSetResults=utf-8security.datasource.username=YYYsecurity.datasource.password=XXXXXX# create db schema, values are none, validate, update, create, and create-drop. #spring.jpa.hibernate.ddl-auto=createspring.jpa.hibernate.ddl-auto=update#spring.jpa.hibernate.ddl-auto=nonespring.jpa.generate-ddl=true# Naming strategyspring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy# The SQL dialect makes Hibernate generate better SQL for the chosen databasespring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
1 回答

蝴蝶刀刀
TA貢獻1801條經驗 獲得超8個贊
訣竅是使用具有
@PropertySources({ @PropertySource("classpath:application.properties") })
注解。然后,在創(chuàng)建 LocalContainerEntityManagerFactoryBean 的方法中,您可以拉取和設置在 application.properties 文件中定義的值
properties.put("spring.jpa.hibernate.naming.physical-strategy", env.getProperty("spring.jpa.hibernate.naming.physical-strategy"));
添加回答
舉報
0/150
提交
取消