【问题标题】:Regex with SpEl usage使用 SpEl 的正则表达式
【发布时间】:2023-03-06 06:53:01
【问题描述】:

如何在 SpEL 中使用正则表达式?

希望将系统属性与 SpEL 和正则表达式一起附加。

预期输出:devInmessagebase/devInmessagetest/devInmessagesample

dev :'env' 变量

消息:来自属性文件(in.topic.mesge)

星号(*):base/test/sample(任何作为后缀)

尝试了以下方法和许多其他方法,但没有奏效。有什么建议吗?

 <int-kafka:consumer-configuration group-id="default3" value-decoder="kafkaSpecificDecoder" 
            key-decoder="kafkaReflectionDecoder" max-messages="10"> 
            <int-kafka:topic-filter pattern="${systemProperties['env'] + in.topic.mesge.'*'}" streams="4" exclude="false" /> </int-kafka:consumer-configuration>

【问题讨论】:

    标签: regex spring spring-integration spring-el


    【解决方案1】:

    pattern 属性的正确语法是:

    pattern="#{systemProperties['env'] + '${in.topic.mesge}' + '.*'}"
    

    【讨论】:

    • 嗨@Garry Russell,感谢您的回复。出现以下错误。嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名称为“(内部 bean)#43c0b942”的 bean 时出错:bean 实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 bean 类 [org.springframework.integration.kafka.support.TopicFilterConfiguration]:构造函数抛出异常;嵌套异常是 java.lang.RuntimeException: dev${in.topic.mesge}.* is an invalid regex.
    • 您需要&lt;context:property-placeholder/&gt; 来添加配置器来解析占位符。它需要指向您的属性文件。
    • 我有属性文件。如果我只提到
    • 我想你一定是弄错了。打开 org.springframework 的调试日志并观察属性解析。
    • 我更改了test case here,并且在使用-Dfoo=bar 运行时对我来说效果很好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-14
    • 2014-03-29
    • 1970-01-01
    • 2017-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多