JHipster 7.1.0:无法使用 jdl-import,在寻找 otherEntity User 时抛出错误
Posted
技术标签:
【中文标题】JHipster 7.1.0:无法使用 jdl-import,在寻找 otherEntity User 时抛出错误【英文标题】:JHipster 7.1.0: Failed to use jdl-import, throws Error looking for otherEntity User at 【发布时间】:2021-09-27 18:14:16 【问题描述】:我正在使用 java Openjdk 11.0.11、JHipster 7.1.0 和节点 v14.17.3 我正在创建一个简单的微服务(一个后端和一个网关),但 JHipster 无法使用 jdl 命令(jdl-import)创建,它会抛出
Error: Error looking for otherEntity User at Tag,Product,Blog,Post
at /Users/carestra/.nvm/versions/node/v14.17.3/lib/node_modules/generator-jhipster/generators/entity/index.js:560:19
at Array.forEach (<anonymous>)
at EntityGenerator.loadRelationships (/Users/carestra/.nvm/versions/node/v14.17.3/lib/node_modules/generator-jhipster/generators/entity/index.js:556:36)
at Object.<anonymous> (/Users/carestra/.nvm/versions/node/v14.17.3/lib/node_modules/generator-jhipster/node_modules/yeoman-generator/lib/index.js:1024:25)
at /Users/carestra/.nvm/versions/node/v14.17.3/lib/node_modules/generator-jhipster/node_modules/run-async/index.js:49:25
at new Promise (<anonymous>)
at /Users/carestra/.nvm/versions/node/v14.17.3/lib/node_modules/generator-jhipster/node_modules/run-async/index.js:26:19
at runLoop.add.once.once (/Users/carestra/.nvm/versions/node/v14.17.3/lib/node_modules/generator-jhipster/node_modules/yeoman-generator/lib/index.js:1025:11)
at Immediate.<anonymous> (/Users/carestra/.nvm/versions/node/v14.17.3/lib/node_modules/generator-jhipster/node_modules/grouped-queue/lib/subqueue.js:48:34)
at processImmediate (internal/timers.js:464:21)
INFO! Generator app child process exited with code 1
ERROR! Error executing app --reproducible --no-force --with-entities --no-dry-run --no-whitespace --no-bail --no-skip-regenerate --no-skip-yo-resolve --from-jdl --no-skip-cache --no-skip-install --no-force-install --no-ask-answered --no-defaults --no-skip-git
Error: Error executing app --reproducible --no-force --with-entities --no-dry-run --no-whitespace --no-bail --no-skip-regenerate --no-skip-yo-resolve --from-jdl --no-skip-cache --no-skip-install --no-force-install --no-ask-answered --no-defaults --no-skip-git
at ChildProcess.<anonymous> (/Users/carestra/.nvm/versions/node/v14.17.3/lib/node_modules/generator-jhipster/cli/import-jdl.js:194:16)
at ChildProcess.emit (events.js:375:28)
at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
它确实会创建文件夹 blogBackend、blogGateWat 和 docker-compose .... 但文件夹 blogBackend 是空的。
如果我转到 blogGateWay 并运行:mvn clean install
我也遇到了异常;
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[ERROR] java.util.ServiceConfigurationError: org.junit.platform.launcher.TestExecutionListener: Provider reactor.blockhound.junit.platform.BlockHoundTestExecutionListener could not be instantiated
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:16 min
[INFO] Finished at: 2021-07-20T09:32:12+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M5:test (default-test) on project blog-gate-way: There are test failures.
[ERROR]
[ERROR] Please refer to /Users/carestra/_A/repos/JHipster/microservices/blog1/blogGateWay/target/surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] There was an error in the forked process
[ERROR] java.util.ServiceConfigurationError: org.junit.platform.launcher.TestExecutionListener: Provider reactor.blockhound.junit.platform.BlockHoundTestExecutionListener could not be instantiated
[ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process
[ERROR] java.util.ServiceConfigurationError: org.junit.platform.launcher.TestExecutionListener: Provider reactor.blockhound.junit.platform.BlockHoundTestExecutionListener could not be instantiated
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:733)
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:305)
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:265)
[ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1314)
[ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:1159)
[ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:932)
[ERROR] at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
[ERROR] at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
[ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
[ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
[ERROR] at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
[ERROR] at org.apache.maven.cli.MavenCli.execute(MavenCli.java:957)
[ERROR] at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
[ERROR] at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
[ERROR] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[ERROR] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR] at java.base/java.lang.reflect.Method.invoke(Method.java:566)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
[ERROR]
[ERROR] -> [Help 1]
[ERROR]
我会将实例化的错误发布为separate question。
知道如何解决这个问题吗?
这是我使用的 jdl 文件 (blog.jdl):
application
config
applicationType gateway,
baseName blogGateWay,
packageName com.carestra.learn.jhipster.gateway,
authenticationType jwt,
serviceDiscoveryType eureka,
buildTool maven,
reactive true, // default true
skipClient false,
skipServer false,
skipUserManagement false,
databaseType sql,
prodDatabaseType postgresql,
devDatabaseType h2Disk,
cacheProvider ehcache,
testFrameworks [cypress]
entities *
application
config
applicationType microservice,
baseName blogBackend,
packageName com.carestra.learn.jhipster.backend,
authenticationType jwt,
serviceDiscoveryType eureka,
buildTool maven,
reactive true,
skipClient true,
skipUserManagement true,
clientFramework react,
databaseType sql,
prodDatabaseType postgresql,
devDatabaseType h2Disk,
cacheProvider hazelcast,
enableHibernateCache true,
testFrameworks [cypress]
entities *
entity Blog
name String required minlength(3)
handle String required minlength(2)
entity Post
title String required
content TextBlob required
date Instant required
entity Tag
name String required minlength(2)
entity Product
title String required
price BigDecimal required min(0)
image ImageBlob
relationship ManyToOne
Bloguser(login) to User
Postblog(name) to Blog
relationship ManyToMany
Posttag(name) to Tagpost
microservice * with blogBackend
deployment
deploymentType docker-compose
appsFolders [blogGateWay, blogBackend]
dockerRepositoryName "carestra"
serviceDiscoveryType eureka
重现步骤: 1 - 创建文件夹博客 2 - 移动到文件夹博客 3 - 运行:jhipster jdl blog.jdl 4 - 移动到 blogGateWay 5 - 运行:mvn clean install
运行:jhpster info om 文件夹博客给我;
jhipster info
INFO! Using JHipster version installed globally
Welcome to the JHipster Information Sub-Generator
##### **JHipster Version(s)**
```
/<intentionally removed info>/blog
└── (empty)
```
cat: no such file or directory: .yo-rc.json
##### **JHipster configuration, a `.yo-rc.json` file generated in the root folder**
<details>
<summary>.yo-rc.json file</summary>
<pre>
</pre>
</details>
##### **JDL for the Entity configuration(s) `entityName.json` files generated in the `.jhipster` directory**
<details>
<summary>JDL entity definitions</summary>
<pre>
</pre>
</details>
##### **Environment and Tools**
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment AdoptOpenJDK-11.0.11+9 (build 11.0.11+9)
Eclipse OpenJ9 VM AdoptOpenJDK-11.0.11+9 (build openj9-0.26.0, JRE 11 Mac OS X amd64-64-Bit Compressed References 20210421_957 (JIT enabled, AOT enabled)
OpenJ9 - b4cc246d9
OMR - 162e6f729
JCL - 7796c80419 based on jdk-11.0.11+9)
git version 2.23.0
node: v14.17.3
npm: 6.14.13
Docker version 20.10.7, build f0df350
docker-compose version 1.29.2, build 5becea4c
No change to package.json was detected. No package manager install will be executed.
Congratulations, JHipster execution is complete!
Sponsored with ❤️ by @oktadev.
运行:jhpster info om 文件夹 blogGateWay 给我;
jhipster info
INFO! Using JHipster version installed locally in current project's node_modules
Welcome to the JHipster Information Sub-Generator
##### **JHipster Version(s)**
```
blog-gate-way@0.0.1-SNAPSHOT /<intentional removed>/blog/blogGateWay
└── (empty)
```
##### **JHipster configuration, a `.yo-rc.json` file generated in the root folder**
<details>
<summary>.yo-rc.json file</summary>
<pre>
"generator-jhipster":
"authenticationType": "jwt",
"clientFramework": "angularX",
"serverPort": "8080",
"serviceDiscoveryType": "eureka",
"skipUserManagement": false,
"withAdminUi": true,
"baseName": "blogGateWay",
"buildTool": "maven",
"databaseType": "sql",
"devDatabaseType": "h2Disk",
"cacheProvider": "no",
"enableHibernateCache": false,
"enableSwaggerCodegen": false,
"enableTranslation": true,
"jhiPrefix": "jhi",
"languages": ["en"],
"messageBroker": false,
"prodDatabaseType": "postgresql",
"searchEngine": false,
"skipClient": false,
"testFrameworks": ["cypress"],
"websocket": false,
"applicationType": "gateway",
"packageName": "com.carestra.learn.jhipster.gateway",
"packageFolder": "com/carestra/learn/jhipster/gateway",
"reactive": true,
"skipServer": false,
"jhipsterVersion": "7.1.0",
"clientPackageManager": "npm",
"dtoSuffix": "DTO",
"entitySuffix": "",
"clientTheme": "none",
"clientThemeVariant": "",
"applicationIndex": 0,
"applications":
"blogBackend":
"serverPort": "8081",
"applicationIndex": 1
,
"skipCheckLengthOfIdentifier": false,
"skipFakeData": false,
"blueprints": [],
"otherModules": [],
"pages": [],
"nativeLanguage": "en",
"creationTimestamp": 1626765856461,
"jwtSecretKey": "YourJWTSecretKeyWasReplacedByThisMeaninglessTextByTheJHipsterInfoCommandForObviousSecurityReasons",
"devServerPort": 4200,
"entities": ["Tag", "Product", "Blog", "Post"],
"lastLiquibaseTimestamp": 1626766096000
</pre>
</details>
##### **JDL for the Entity configuration(s) `entityName.json` files generated in the `.jhipster` directory**
<details>
<summary>JDL entity definitions</summary>
<pre>
entity Tag
name String required minlength(2)
entity Product
title String required
price BigDecimal required min(0)
image ImageBlob
entity Blog
name String required minlength(3)
handle String required minlength(2)
entity Post
title String required
content TextBlob required
date Instant required
relationship ManyToOne
Bloguser(login) to User
Postblog(name) to Blog
relationship ManyToMany
Posttag(name) to Tagpost
microservice Tag, Product, Blog, Post with blogBackend
clientRootFolder Tag, Product, Blog, Post with blogBackend
</pre>
</details>
##### **Environment and Tools**
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment AdoptOpenJDK-11.0.11+9 (build 11.0.11+9)
Eclipse OpenJ9 VM AdoptOpenJDK-11.0.11+9 (build openj9-0.26.0, JRE 11 Mac OS X amd64-64-Bit Compressed References 20210421_957 (JIT enabled, AOT enabled)
OpenJ9 - b4cc246d9
OMR - 162e6f729
JCL - 7796c80419 based on jdk-11.0.11+9)
git version 2.23.0
node: v14.17.3
npm: 6.14.13
Docker version 20.10.7, build f0df350
docker-compose version 1.29.2, build 5becea4c
No change to package.json was detected. No package manager install will be executed.
Congratulations, JHipster execution is complete!
Sponsored with ❤️ by @oktadev.
【问题讨论】:
【参考方案1】:发生错误是因为您使用的是 JWT 身份验证类型而不是 OAuth2。
对于OAuth2,微服务中有一种机制可以从token中提取用户数据并保存到服务的数据库中。
不幸的是,我找不到任何关于此的文档,所以我阅读了以下代码 https://github.com/jhipster/generator-jhipster/blob/main/utils/entity.js这里判断是否激活这个用户快照的测试是:
entityWithConfig.saveUserSnapshot =
entityWithConfig.applicationType === MICROSERVICE &&
entityWithConfig.authenticationType === OAUTH2 &&
hasBuiltInUserField &&
entityWithConfig.dto === NO_MAPPER;
可以看到还有一个条件就是不使用DTO。
这种机制有一些限制,因为只有在调用服务 API 时才会更新用户的数据,您可以想象这样的情况:用户已在网关中更新,而后台作业正在使用旧版本的服务中运行用户。
对于 JWT,这还没有实现,因为令牌不包含足够的用户数据,它只包含登录名和角色。
因此,使用 JWT,您能否在 Blog 中仅存储用户的 ID(或登录名)而不定义与用户实体的关系,因为它仅存在于网关数据库中。
【讨论】:
感谢您的 cmets @marziou 但在 JHipsters 教程视频“使用 Spring Boot 和 JHipster 构建反应式 Java 微服务”(developer.okta.com/blog/2021/01/20/…) 他们使用相同的模型设置......除了在我的例如我使用一个微服务(我没有使用 store-microservice)。在教程中他们使用相同的实体和相同的关系,为什么它在教程中起作用?是的,我理解隔离部分,但为什么它在教程中有效? 你是对的,但本教程的不同之处在于你在使用 JWT 而他们使用 OAuth2,我编辑了我的答案。 感谢@gmarziou 的更新和解释......我也打算使用 DTO,所以现在我知道我不会使用的限制定义与网关用户实体的关系,更好使用用户 ID。【参考方案2】:几乎相同的错误花了我一个小时才找到解决方案。在我的情况下,我写错了关系实体名称,所以写正确的关系实体名称就可以了。我在写:
ChatToSearch
但我的实体名称是:
ChatsToSearch
所以,我已经更正了它并且成功了!
【讨论】:
以上是关于JHipster 7.1.0:无法使用 jdl-import,在寻找 otherEntity User 时抛出错误的主要内容,如果未能解决你的问题,请参考以下文章
JHipster - 在 AWS Beanstalk 中发布部署 Jhipster 注册表
jhipster - 将应用程序部署到 Heroku 后无法运行本地开发配置文件
无法根据日期字段获取记录 = jhipster 中的当前日期
jhipster 刷新 url 导致“无法获取 /user-management”
Jhipster - 在 docker 主机上部署除网关本身、混合 Docker 和本地部署之外的所有内容时,无法使用网关应用程序