我已经生成了一个配置为jhipster 4.6.2的微服务。 我正在使用Docker(使用Virtualbox)运行Consul。
因此,它不在localhost上运行(例如,使用192.168.99.100)。
因此我修改了我的微服务的application-dev.yml来设置这样的主机:
云: 领事: 发现: prefer-ip-address:true 主持人:192.168.99.100 港口:8500
...但是当我启动微服务时,它仍然试图连接到localhost(即不考虑下面的属性)。 然后我得到了这个例外:
com.ecwid.consul.transport.TransportException: org.apache.http.conn.HttpHostConnectException: 连接到localhost:8500 [localhost / 127.0.0.1,localhost / 0:0:0:0:0:0:0:1,localhost / fe80:0:0:0:0:0:0:1%1]失败: 连接被拒绝
有什么想法吗?
谢谢!
我的配置jhipster:
{
"generator-jhipster": {
"promptValues": {
"packageName": "org.fge.msconsul"
},
"jhipsterVersion": "4.6.2",
"baseName": "msconsul",
"packageName": "org.fge.msconsul",
"packageFolder": "org/fge/msconsul",
"serverPort": "8082",
"authenticationType": "jwt",
"hibernateCache": "hazelcast",
"clusteredHttpSession": false,
"websocket": false,
"databaseType": "sql",
"devDatabaseType": "h2Disk",
"prodDatabaseType": "postgresql",
"searchEngine": false,
"messageBroker": false,
"serviceDiscoveryType": "consul",
"buildTool": "maven",
"enableSocialSignIn": false,
"jwtSecretKey": "replaced-by-jhipster-info",
"enableTranslation": false,
"applicationType": "microservice",
"testFrameworks": [],
"jhiPrefix": "jhi",
"skipClient": true,
"skipUserManagement": true,
"clientPackageManager": "yarn"
}
}
</details>
##### **JDL for the Entity configuration(s) `entityName.json` files generated in the `.jhipster` directory**
##### **Environment and Tools**
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)
git version 2.11.0 (Apple Git-81)
node: v7.4.0
npm: 5.0.3
bower: 1.8.0
gulp:
[22:45:50] CLI version 3.9.1
yeoman: 2.0.0
yarn: 0.27.5
Docker version 17.05.0-ce, build 89658be
docker-compose version 1.13.0, build 1719ceb
Execution complete
答案 0 :(得分:2)
Spring Cloud有一个bootstrap phase,可以从外部源加载配置属性。
src/main/resources/bootstrap*.yml
是您必须配置如何连接到Consul的文件。
答案 1 :(得分:1)
您还可以在application.properties中提及下面的领事主持人,我已经确认这是有效的
spring.cloud.consul.host=http://hostname
spring.cloud.consul.port=8500
提及这个的最好方法是bootstrap.yml,它在加载任何.properties之前首先加载