小编I-L*_*Kuo的帖子

Spring Cloud Config 属性的加载优先级是什么?

Spring 有明确的加载外部化配置的顺序。

  1. 主目录中的 Devtools 全局设置属性(当 devtools 处于活动状态时为 ~/.spring-boot-devtools.properties)。
  2. 测试中的 @TestPropertySource 注释。
  3. 测试中的 @SpringBootTest#properties 注释属性。
  4. 命令行参数。
  5. 来自 SPRING_APPLICATION_JSON 的属性(嵌入在环境变量或系统属性中的内联 JSON)。
  6. ServletConfig 初始化参数。
  7. ServletContext 初始化参数。
  8. 来自 java:comp/env 的 JNDI 属性。
  9. Java 系统属性 (System.getProperties())。
  10. 操作系统环境变量。
  11. 仅在 random.* 中具有属性的 RandomValuePropertySource。
  12. 打包 jar 之外的特定于配置文件的应用程序属性(application-{profile}.properties 和 YAML 变体)。
  13. 打包在 jar 中的特定于配置文件的应用程序属性(application-{profile}.properties 和 YAML 变体)。
  14. 打包 jar 之外的应用程序属性(application.properties 和 YAML 变体)。
  15. 打包在 jar 中的应用程序属性(application.properties 和 YAML 变体)。
  16. @Configuration 类上的 @PropertySource 注释。
  17. 默认属性(通过设置 SpringApplication.setDefaultProperties 指定)。

然而,来自Spring Cloud Config 的配置似乎有明显的遗漏。有谁知道 Spring Cloud Config 在上面的位置

java spring spring-boot spring-config

13
推荐指数
1
解决办法
3293
查看次数

如何从JavaScript模块模式中的私有函数中调用公共函数

如何从JavaScript模块模式中的私有函数中调用公共函数?

例如,在以下代码中,

var myModule = (function() {
    var private1 = function(){
        // How to call public1() here?
        // this.public1() won't work
    }

    return {
        public1: function(){ /* do something */}
    }
})();
Run Code Online (Sandbox Code Playgroud)

此问题之前已被问过两次 ,每个问题都有不同的接受答案.

  1. 在返回之前保存对返回对象的引用,然后使用该引用访问公共方法.见答案.
  2. 在闭包中保存对public方法的引用,并使用它来访问public方法.见答案.

虽然这些解决方案有效,但从OOP的角度来看,它们并不令人满意.为了说明我的意思,让我们用这些解决方案中的每个解决方案对雪人进行具体实现,并将它们与简单的对象文字进行比较.

雪人1:保存对返回对象的引用

var snowman1 = (function(){
  var _sayHello = function(){
    console.log("Hello, my name is " + public.name());
  };

  var public = {
    name: function(){ return "Olaf"},
    greet: function(){
      _sayHello();
    }
  };
  return public;
})()
Run Code Online (Sandbox Code Playgroud)

雪人2:保存对公共功能的引用

var snowman2 …
Run Code Online (Sandbox Code Playgroud)

javascript module-pattern

8
推荐指数
1
解决办法
2313
查看次数

用角度显示模块模式

今天的代码让我再次疯狂,特别是Angular与Angular服务中的Revealing Module Pattern.当我开始时,我发现它没有任何问题...现在除了不工作......我不知道.任何方式都知道我想知道它是否有角度或者我做了一些愚蠢的事情.这是代码:

angular.module('homeAdmin.services', [])
.factory('dataService', function ($http, $q) {
    'use strict';
    function _contentTypes(){
        var intialized = false;
        var _models = [];
        function _isReady() {
            return intialized;
        };
        return {
            isReady: _isReady
        };
    };

    return {
        contentTypes: _contentTypes
    };
});
Run Code Online (Sandbox Code Playgroud)

这就是所谓的地方:

var contentTypeCtrl = ['$scope','$http','$window','dataService', function ($scope, $http, $window, dataService) {
'use strict';
$scope.isBusy = false;
$scope.data = dataService;
$scope.contentType = {};

$scope.name = 'Content Type';
$scope.init = function () {
    console.log('contentTypeCtrl initialized');
};

if (dataService.contentTypes.isReady() == false) {
    console.log("Hello …
Run Code Online (Sandbox Code Playgroud)

javascript revealing-module-pattern angularjs

2
推荐指数
1
解决办法
2263
查看次数