JHipster Registry 拒绝网关和微服务

JHipster Registry rejects gateways and microservices

我正在尝试将 JHipster 用于使用微服务的项目,但最新的 JHipster Registry 不允许我的网关或微服务访问配置服务器并拒绝它们。

我安装了 JHipster Vagrant DevBox,然后使用 docker run -p 8761:8761 jhipster/jhipster-registry 到 运行 JHipster 注册表。 然后,我在 this 之后生成了一个网关和 2 个微服务,并且成功了。

但后来我想使用来自 GitHub 的 JHipster Registry,所以我克隆了它并 运行 嵌入了它(显然它已同时更新到 2.0.0)。遗憾的是,网关和微服务无法访问此注册表。他们仍然能够访问 Docker 图像注册表(我想 Docker 没有更新它)。但是因为它更漂亮,而且可能是最新的,所以我想使用最新版本的注册表,与 GitHub 中的注册表相同。所以我尝试用 docker pull 更新 Docker 图像 Jhipster Registry。现在它不适用于注册表 - Docker 图像或 GitHub 克隆。

当注册中心 运行ning 而我 运行 网关或微服务时,我得到 6 倍:

2016-05-10 15:39:07.511 DEBUG 20706 --- [           main] s.n.www.protocol.http.HttpURLConnection  : sun.net.www.MessageHeader@86ba8f5 pairs: {GET /config/gateway/dev/master HTTP/1.1: null}{Accept: application/json, application/*+json}{User-Agent: Java/1.8.0_91}{Host: localhost:8761}{Connection: keep-alive}
2016-05-10 15:39:07.522 DEBUG 20706 --- [           main] s.n.www.protocol.http.HttpURLConnection  : sun.net.www.MessageHeader@43c7802510 pairs: {null: HTTP/1.1 401 Unauthorized}{Server: Apache-Coyote/1.1}{X-Content-Type-Options: nosniff}{X-XSS-Protection: 1; mode=block}{Cache-Control: no-cache, no-store, max-age=0, must-revalidate}{Pragma: no-cache}{Expires: 0}{Content-Type: application/json;charset=UTF-8}{Transfer-Encoding: chunked}{Date: Tue, 10 May 2016 15:39:07 GMT}

然后我得到一个错误:

2016-05-10 15:39:13.781 ERROR 20706 --- [           main] o.s.boot.SpringApplication               : Application startup failed

然后我得到 Java 个异常:

java.lang.IllegalStateException: Could not locate PropertySource and the fail fast property is set, failing
at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.locate(ConfigServicePropertySourceLocator.java:110)
at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator$$FastClassBySpringCGLIB$$fa44b2a.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.retry.interceptor.RetryOperationsInterceptor.doWithRetry(RetryOperationsInterceptor.java:74)
at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:263)
at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:154)
at org.springframework.retry.interceptor.RetryOperationsInterceptor.invoke(RetryOperationsInterceptor.java:101)
at org.springframework.retry.annotation.AnnotationAwareRetryOperationsInterceptor.invoke(AnnotationAwareRetryOperationsInterceptor.java:118)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)
at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator$$EnhancerBySpringCGLIB$$a0abff82.locate(<generated>)
at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.initialize(PropertySourceBootstrapConfiguration.java:89)
at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:640)
at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:343)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
at com.soprasteria.example.GatewayApp.main(GatewayApp.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:478)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.web.client.HttpClientErrorException: 401 Unauthorized
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91)
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:641)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:597)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:557)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:475)
at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.getRemoteEnvironment(ConfigServicePropertySourceLocator.java:130)
at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.locate(ConfigServicePropertySourceLocator.java:81)
... 23 common frames omitted

[WARNING] 
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:478)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: Could not locate PropertySource and the fail fast property is set, failing
at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.locate(ConfigServicePropertySourceLocator.java:110)
at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator$$FastClassBySpringCGLIB$$fa44b2a.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.retry.interceptor.RetryOperationsInterceptor.doWithRetry(RetryOperationsInterceptor.java:74)
at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:263)
at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:154)
at org.springframework.retry.interceptor.RetryOperationsInterceptor.invoke(RetryOperationsInterceptor.java:101)
at org.springframework.retry.annotation.AnnotationAwareRetryOperationsInterceptor.invoke(AnnotationAwareRetryOperationsInterceptor.java:118)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)
at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator$$EnhancerBySpringCGLIB$$a0abff82.locate(<generated>)
at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.initialize(PropertySourceBootstrapConfiguration.java:89)
at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:640)
at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:343)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
at com.soprasteria.example.GatewayApp.main(GatewayApp.java:73)
... 6 more
Caused by: org.springframework.web.client.HttpClientErrorException: 401 Unauthorized
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91)
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:641)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:597)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:557)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:475)
at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.getRemoteEnvironment(ConfigServicePropertySourceLocator.java:130)
at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.locate(ConfigServicePropertySourceLocator.java:81)
... 23 more

最后是 BUILD FAILURE 和 Maven 错误:

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.3.3.RELEASE:run (default-cli) on project gateway: An exception occurred while running. null: InvocationTargetException: Could not locate PropertySource and the fail fast property is set, failing: 401 Unauthorized -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

在注册表的 shell 中,我也收到了这行 6 次:

2016-05-10 15:39:07.519 DEBUG 17958 --- [io-8761-exec-10] i.g.j.r.s.Http401UnauthorizedEntryPoint  : Pre-authenticated entry point called. Rejecting access

我尝试更新所有内容,目前我正在尝试降级(因为文档说 "we recommend you use the same version tag as the one you use for your JHipster generator",但我不认为它会起作用,因为 JHipster Registry 的最新版本是 2.0.0 并且JHipster 生成器在 3.0 版本中引入了微服务),我也尝试过将 secret 从 central-server-config 直接复制到应用程序的配置中,但显然无济于事。

你能帮我解决这个问题吗?

非常感谢您。

编辑:

我尝试使用 npm install -g generator-jhipster 将 JHipster 更新到 3.2.1,这显然有效,但是当我 运行 yo jhipster 时,Yeoman 仍然使用 JHipster 3.1.0。实际上,即使我用 npm uninstall -g generator-jhipster 卸载 JHipster,Yeoman 仍然可以使用 JHipster 3.1.0...

编辑:

如果我在本地重新安装所有内容(在我使用 yo jhipster 的目录中),它会正常工作。 但是,我仍然无法在 Yeoman 中全局更新 JHipster。当我尝试使用 npm install -g generator-jhipster 时,它会将 JHipster 全局更新为 3.2.1,但 Yeoman 仍使用 3.1.0。如果我尝试使用 yo/"Update your generators"/generator-jhipster 更新 JHipster,我会得到一个错误:

npm WARN deprecated npmconf@2.1.2: this package has been reintegrated into npm and is now out of date with respect to npm
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/generator-jhipster
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
/usr/local/lib
└── generator-jhipster@3.2.1 

npm ERR! Linux 3.13.0-85-generic
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "generator-jhipster"
npm ERR! node v4.4.4
npm ERR! npm  v3.8.9
npm ERR! path /usr/local/lib/node_modules/generator-jhipster
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access

npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules/generator-jhipster'
npm ERR!     at Error (native)
npm ERR!  { [Error: EACCES: permission denied, access '/usr/local/lib/node_modules/generator-jhipster']
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib/node_modules/generator-jhipster' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/vagrant/npm-debug.log

I've just updated your generators. Remember, you can update
a specific generator with npm by running:

    npm install -g generator-_______

使用 sudo 会做同样的事情,当我尝试 运行 yo:

sudo su 给我这个
/usr/local/lib/node_modules/yo/node_modules/configstore/index.js:53
                throw err;
                ^

Error: EACCES: permission denied, open '/root/.config/configstore/insight-yo.json'
You don't have access to this file.

    at Error (native)
    at Object.fs.openSync (fs.js:549:18)
    at Object.fs.readFileSync (fs.js:397:15)
    at Object.create.all.get (/usr/local/lib/node_modules/yo/node_modules/configstore/index.js:34:26)
    at Object.Configstore (/usr/local/lib/node_modules/yo/node_modules/configstore/index.js:27:44)
    at new Insight (/usr/local/lib/node_modules/yo/node_modules/insight/lib/index.js:37:34)
    at Object.<anonymous> (/usr/local/lib/node_modules/yo/lib/cli.js:163:11)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)

编辑:

好的,即使是本地安装也工作... 好吧,网关确实可以访问注册表,但是当我尝试访问 localhost:8080 时它会显示一个调试页面。 实际上,在生成过程中,我又得到了一个 permission denied,并且缺少依赖项 (gulp-rev)。

我刚刚在 DevBox GitHub 页面上看到了这个:"It is wise to use a tag to have a stable version: the JHipster DevBox tags are the same as the JHipster Generator tags, so using the DevBox v3.2.0 also means using the generator v3.2.0",所以也许我会删除并重新下载 DevBox...

这是因为您将JHipster Registry升级到了2.0.0版本。这个新版本是安全的,这就是为什么你有 401 "unauthenticated" 错误,因为你没有提供任何 login/password 连接。

3 个解决方案:

  • 继续使用与您的 JHipster 版本匹配的旧 JHipster Registry 版本。
  • 将 login/password(默认情况下为 admin/admin)添加到您的 Eureka 和 Spring Cloud Config URL。有关保护 JHipster Registry 的详细文档是 here - 在撰写本文时它还不完整,但我会尽快更新它
  • 更新到 JHipster v3.2.1,旨在与 JHipster Registry v2.0.0 一起使用,所有内容都将自动配置。

我在使用 IntelliJ IDEA​​ 在本地使用从 github 运行 提取的最新 JHipster Registry 时发现了相同的行为——服务器会启动,但前端不会提供服务.

原来是 Run/Debug 配置中空白工作目录的问题。填充后,可以从 IDE.

找到工作