【问题标题】:Magnolia 5.7.9 module configurationMagnolia 5.7.9 模块配置
【发布时间】:2021-03-03 19:40:09
【问题描述】:

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

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

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

我正在运行 Magnolia 5.7.9

更新:

我的模块类的完成方式与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;
    }

   
}

我有一个以编程方式查询字符串值是否在列表中的类。该列表似乎是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.

【问题讨论】:

  • 你能把你的模块类粘贴到这里吗?例如,您是否有匹配 colorsEnabled 的 getter 和 setter?

标签: magnolia


【解决方案1】:

FooBar 类不在 YAML 配置中。模块在哪里 配置从哪里获取colorsEnabled属性?

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

列表似乎始终为空。

是的,因为您使用配置工作区中的值覆盖了 yaml 中的值(或者您在工作区中只有一个而 yaml 中没有?)并且您仍然以 yaml 格式编写属性列表,而不是使用适合的语法jcr (这将是 contentNode 称为 excludes 在该节点下具有 4 个属性,每个属性都是代表各个颜色的名称/值对。不幸的是,文档没有显示出如此明显的差异,因此很容易在那里犯错。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多