Magnolia 5.7.9 模块配置

Magnolia 5.7.9 module configuration

在文档中用于 magnolia 模块配置的 example 我不确定为什么 private boolean colorsEnabled; 用于 FooBar class 不在 YAML 配置中。模块配置从哪里得到colorsEnabled属性?

maxSize: 25
welcomeMessage: Hello world
fooBar:
  colors: [red, green, blue]

此外,当我以编程方式检索 List<String> list = fooBar.getColors(); 时,我得到列表的 null

我是运行玉兰5.7.9.

更新:

我的模块 class 的完成方式与 documentation 和上述示例中描述的方式相同。

public class XxxVersioning implements ModuleLifecycle {
    
 private Excludes excludes;         
    
 public Excludes getExcludes() {
    return excludes;
}



public void setExcludes(Excludes excludes) {
    this.excludes = excludes;
}



public class Excludes {
    private String red;
    private String green;
    
   public String getRed() {
        return red;
    }
    public void setRed(String red) {
        this.red = red;
    }
    public String getGreen() {
        return green;
    }
    public void setGreen(String green) {
        this.green = green;
    }

   
}

我有一个 class 以编程方式查询字符串值是否在列表中。该列表似乎是 null.

/**
* Find if template name for the component in the module exception list
* @param String templateName
* @return Boolean true if templateName in the module exception-list
*/
public Boolean isComponentException(String templateName) {
        // get the (singleton) instance of the module
        //  On the module class instance call the getter methods of the module bean properties.
        XxxVersioning moduleInstance = xxxVersionProvider.get();
            
        // access the modules RenderingExcludes bean
        XxxVersioning.Excludes excludes =  moduleInstance.getExcludes();
    
        String green = excludes.getGreen();
            
        return true;


        }

解决方案: 对于引导程序,我在 [此处][5] 根据此文档找到了文档

All bootstrap files are only imported once!

    Webapp-based bootstrap files are imported during the first run of the webapp when the Magnolia instance gets installed.
    Module-based bootstrap files are imported during the installation of the module.

If you want to import bootstrap files on every start up of the Magnolia instance or of a module, you must use custom installation tasks which are executed by the Module version handler or Module start up classes.

FooBar class is not in the YAML configuration. Where does the module configuration get the colorsEnabled property from?

首先检查 YAML/FS,然后从 JCR 配置(存储库中的 config 工作区)检查。或者,如果该名称的 属性 不存在,它将采用默认值。 更多关于检查资源的顺序 here.

The list appears to be always null.

是的,因为您用配置工作区中的值覆盖了 yaml 的值(或者您在工作区中只有一个值而 yaml 中什么也没有?)并且您仍然以 yaml 格式编写 属性 列表而不是使用适合 jcr 的语法(这将 contentNode 称为 excludes,该节点下有 4 个属性,每个属性都是 name/value 对,代表各个颜色。不幸的是,文档没有显示它们有何不同这么清楚,所以很容易出错。

无论如何,作为一种好的做法,您应该选择存储配置的位置 - 在 repo 或 yaml 中。我建议 FS 中的 yaml 配置,因为它允许您从外部更改配置,即使您的应用程序已损坏。此外,将该文件保存在 git 或其他 VCS 中并跟踪其更改的正确历史记录会更容易。