zoukankan      html  css  js  c++  java
  • Cuba获取属性文件中的配置

      最直接的办法是,使用AppContext.getProperty("cuba.trustedClientPassword");

      可以获取到系统中的web模块下的wep-app.properties和 core模块下的app.properties文件中的配置信息(core是业务,web是UI),但是不推荐这么使用。

      推荐使用Config代替AppContext

      在web模块中使用WebAuthConfig
      @Inject
      private WebAuthConfig webAuthConfig;

      获取:

      webAuthConfig.getTrustedClientPassword();

      在core模块中使用ServerConfig
      @Inject
      private ServerConfig serverConfig;

      获取:

      serverConfig.getTrustedClientPassword();

      这两个类有同样的这个方法

    @Source(type = SourceType.APP)
    public interface WebAuthConfig extends Config {
    @Property("cuba.trustedClientPassword")
    @DefaultString("")
    String getTrustedClientPassword();
    }
    
    @Source(type = SourceType.APP)
    public interface ServerConfig extends Config {
    @Property("cuba.trustedClientPassword")
    @DefaultString("")
    String getTrustedClientPassword();
    }

       而cuba.trustedClientPassword = **********,这个配置,是配置在web-app.properties里的。ServerConfig也是可以获取到的。

       注意:这种使用方法只能用在Bean中,而不能在普通的jaca类里,因为要使用到注解,而只有Bean才能被容器管理,才可以使用注解。

    新建属性

      上面的两个属性,都是cuba系统自带的属性,那两个类也是写在jar文件中的。如果是自己新增的需要,需要自定义一个Config类,继承Config类就可以。

      如下: 

    //定义属性类类
    @Source(type= SourceType.DATABASE)
    public interface CAConfig extends Config {
        @Property("ucenter.CA.pdf.sign.enable")
        @DefaultBoolean(false)
        Boolean getCAPDFSignEnable();
    }
    
    //调用时
    @Inject
    private CAConfig caConfig;
    
    //获取 
    caConfig.getCAPDFSignEnable()

    在运行时修改属性

      刚开始把属性获取到以后,直接放到了全局静态变量里了
        public static final String CUBA_TRUSTED_CLIENT_PASSWORD = AppContext.getProperty("cuba.trustedClientPassword");

      但是这样的坏处是:如果在项目运行时修改了属性,就必须重启系统才能生效,这明显是不好的。所以不应该使用上面的方法,而之前的办法在项目运行是进行修改,也会实时得获取到。

      那么怎么修改呢?

      使用【管理员】登陆,在【管理】-【应用程序属性】下可以搜索到:

      编辑:

     

  • 相关阅读:
    linux 命令——19 find (转)
    linux 命令——18 locate (转)
    linux 命令——17 whereis(转)
    linux 命令——16 which(转)
    linux 命令——15 tail (转)
    linux 命令——14 head (转)
    Java for LeetCode 038 Count and Say
    Java for LeetCode 037 Sudoku Solver
    Java for LeetCode 036 Valid Sudoku
    Java for LeetCode 035 Search Insert Position
  • 原文地址:https://www.cnblogs.com/acm-bingzi/p/cubaProperties.html
Copyright © 2011-2022 走看看