阅读Micronaut方面的占位符

问题描述

我想在micronaut中创建一个aspect,以便采用一种通用的方式将事件发送到队列,并带有传递给某些方法的信息以及来自上下文的某些信息,例如方法参数 方法响应 持续时间 例外 请求标头(用于api方法) 等。但是,我想在注释中定义应将哪些数据添加到事件中。我有一个使用spring boot和SpEL的工作示例:

@Event( <- This is the annotation to create the event
     @Detail(key = "salary",value = "#request.salary.toString()"),<- This is the SpEL
     @Detail(key = "ipAddress",value = "#HttpServletRequest.getHeader('x-forwarded-for').split(',')[0]"),<- This gets the client ipAddress from the context
     @Detail(key = "userAgent",value = "#HttpServletRequest.getHeader('user-agent')"") <- This gets the browser

)
public void MyMethod(RequestInformation request){
}

在上面的示例中,仅使用3个属性创建了事件,并以json格式发送到队列

{
 details:[
    "salary":"6000","ipAddress":"180.30.115.62","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML,like Gecko) Version/13.1.2 Safari/605.1.15"
 ]
}

我知道Micronaut不支持SpEL,因为它在documentationSpring Expression Language (SpEL) - SpEL expressions are not supported,property placeholders are however

中指出

我尝试阅读有关属性占位符的信息,但是大多数示例都与从.yml文件获取值有关。

我想知道是否有一种方法可以做类似的事情而无需在micronaut中创建自己的语言。另外,迁移到Spring Boot也是不可行的。

我将感谢您对如何完成此任务的任何帮助,建议或见解。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...