V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
Angzk3488
V2EX  ›  Java

Java Web 工程中 的 系统配置常量的定义

  •  1
     
  •   Angzk3488 · Feb 21, 2019 · 1470 views
    This topic created in 2622 days ago, the information mentioned may be changed or developed.

    方案 1 使用常量类 / 枚举常量 / 接口常量

    方案 2 自定义 properties 文件,再将 properties 加载到 Spring (@Component @PropertySources ) 中,在需要的地方注入对应的 Bean。

    方案 3 自定义 properties 文件, 通过 PropertiesLoaderUtils.loadProperties 将 加载到 静态 Properties 中 , 然后 统统 getProperty(key) 来取值

    方案 1,在后期修改维护上会麻烦一下,但是使用较为方便 ClassName.常量名。 方案 2,维护修改很方便,使用时 需在 当前类注入 Spring Bean,然后调用 get 函数。 方案 3,同样维护时只需更改配置文件 , 使用时 直接 ClassName.config ( Key )。

    还有什么深层次的 优缺点,麻烦大家 指点指点。

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3584 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 11:08 · PVG 19:08 · LAX 04:08 · JFK 07:08
    ♥ Do have faith in what you're doing.