JHipster导入JDL文件引发大量配置冲突问题咨询
问题描述
我是JHipster 7.9.3版本的新手,创建了一个以MySQL为数据库、Angular为前端的单体应用,创建时未选择缓存选项。导入一份极简配置的JDL文件后,出现大量文件冲突,且导入操作将开发数据库改为H2并启用ehcache,这与我的初始配置不符。冲突涉及多个核心文件,现咨询该问题的原因,以及如何配置让JDL导入功能不修改数据库和缓存配置。
初始应用创建配置
? Which *type* of application would you like to create? Monolithic application (recommended for simple projects) ? What is the base name of your application? jdlimporttest ? Do you want to make it reactive with Spring WebFlux? No ? What is your default Java package name? com.mycompany.myapp ? Which *type* of authentication would you like to use? JWT authentication (stateless, with a token) ? Which *type* of database would you like to use? SQL (H2, PostgreSQL, MySQL, MariaDB, Oracle, MSSQL) ? Which *production* database would you like to use? MySQL ? Which *development* database would you like to use? MySQL ? Which cache do you want to use? (Spring cache abstraction) No cache - Warning, when using an SQL database, this will disable the Hibernate 2nd level cache! ? Would you like to use Maven or Gradle for building the backend? Maven ? Do you want to use the JHipster Registry to configure, monitor and scale your application? No ? Which other technologies would you like to use? ? Which *Framework* would you like to use for the client? Angular ? Do you want to generate the admin UI? Yes ? Would you like to use a Bootswatch theme (https://bootswatch.com/)? Default JHipster ? Would you like to enable internationalization support? No ? Please choose the native language of the application English ? Besides JUnit and Jest, which testing frameworks would you like to use? ? Would you like to install other generators from the JHipster Marketplace? No
导入的JDL文件内容
application { config { baseName jdlimporttest, applicationType monolith, packageName com.mycompany.myapp, authenticationType jwt, prodDatabaseType mysql, clientFramework angular } entities * } entity Product { productId String productName String description String price Long specifications String } entity Inventory { id String inStock Integer purchased Integer }
冲突涉及文件
- package.json
- src\main\resources\config\liquibase\master.xml
- pom.xml
- src\main\resources\logback-spring.xml
- src\main\resources\config\application.yml
- src\main\resources\config\application-dev.yml
- src\main\resources\config\application-prod.yml
- src\main\java\com\mycompany\myapp\config\WebConfigurer.java
- src\main\java\com\mycompany\myapp\config\SecurityConfiguration.java
- DatabaseConfiguration.java
- ExceptionTranslator.java
- logback.xml
问题原因与解决方法
问题原因
- JDL的
application配置块中,未明确指定开发数据库类型和缓存提供者,JHipster会使用默认值填充:开发数据库默认H2,缓存默认启用ehcache,直接覆盖了初始项目的配置。 - 当JDL中包含
application块时,导入操作会重新生成整套应用配置文件,和现有项目的自定义配置产生冲突。
解决方法
方法1:完善JDL配置,保持与初始项目一致
修改JDL文件的config块,补充缺失的配置项,确保和初始创建时的设置匹配:
application { config { baseName jdlimporttest, applicationType monolith, packageName com.mycompany.myapp, authenticationType jwt, prodDatabaseType mysql, devDatabaseType mysql, // 新增:指定开发数据库为MySQL cacheProvider no, // 新增:指定不使用缓存 clientFramework angular } entities * }
修改后重新执行导入命令,就能保证配置和初始项目一致,不会产生不必要的冲突。
方法2:仅导入实体,忽略应用配置修改
如果你的JDL只需要新增实体,不需要修改应用配置,可以在导入时添加--ignore-application参数,跳过application块的处理:
jhipster import-jdl your-jdl-file.jdl --ignore-application
这样只会生成实体相关的代码,不会修改数据库、缓存等核心配置文件。
方法3:修复已产生的冲突
如果已经出现文件冲突,先通过版本控制工具(如Git)回滚冲突的配置文件,恢复到初始状态,再选择上述两种方法之一重新导入JDL。
内容的提问来源于stack exchange,提问作者Sanal M
相关产品推荐
相关产品推荐

