【发布时间】:2017-06-10 05:27:50
【问题描述】:
我的AppConfig java 类中有一个配置属性serverName,它从cloud config client 获取值。这个serverName 值用于Java 类和AngularJS Services。这个serverName对于不同的环境有不同的值。
我的问题
目前我正在使用 pcf spring cloud config 和具有不同值的不同配置文件。所以 Java 类访问 serverName 没有问题,但在 AngularJS service 我是 manually changing 将 serverName 值部署到各自的 environment 值之前将其部署到各自的环境。
我的问题
有没有办法将AppConfig 的serverName 属性访问到我的AngularJS Service 中?
AppConfig Java
@EnableConfigurationProperties
@ConfigurationProperties
@RefreshScope
@Configuration
public class AppConfig {
@Value("${external.server.name}")
private String serverName;
}
application.yml
external:
server:
name: localName
my_service.js
angular.module('myApp').factory('myService', ['$http', '$q', '$window', function($http, $q, $window){
var serverName = 'localName';
// for each env deployment make sure the developer changes the value to respective env value, if not the service will fail
.....
}
【问题讨论】:
-
为什么客户端需要服务器名?
-
从angularJS服务调用serverName上的rest服务
-
@KursadGulseven 实际上我正在使用从 my_service.js 到
Rest Controller的$http.get('serverName')进行休息呼叫,所以如果在本地,那么它将是$http.get('http://localhost:8080'), once I deploy this to qat it will be the qaturl. Is there anyway to make rest call fromjs` 到java rest controller?
标签: angularjs spring-mvc spring-boot spring-cloud-config