将动态参数传递给注释? [英] Passing dynamic parameters to an annotation?

查看:34
本文介绍了将动态参数传递给注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下注释:

@ActivationConfigProperty(propertyName = "连接参数",propertyValue = "host=127.0.0.1;port=5445,host=127.0.0.1;port=6600"),公共类 TestMDB 实现 MessageDrivenBean、MessageListener

我想提取每个 IP 地址和端口并将它们存储在文件 jmsendpoints.properties...然后动态加载它们.像这样:

@ActivationConfigProperty(propertyName = "连接参数",propertyValue = jmsEndpointsProperties.getConnectionParameters()),公共类 TestMDB 实现 MessageDrivenBean、MessageListener

有没有办法做到这一点?

解决方案

注释处理器(您正在使用的基于注释的框架)需要实现一种处理占位符的方法.

<小时>

例如,在 Spring

@Value("#{systemProperties.dbName}")

这里 Spring 实现了一种解析特定语法的方法,在这种情况下,它转换为类似于 System.getProperty("dbName");

I am using the following annotation:

@ActivationConfigProperty(
    propertyName = "connectionParameters", 
    propertyValue = "host=127.0.0.1;port=5445,host=127.0.0.1;port=6600"),
public class TestMDB implements MessageDrivenBean, MessageListener

I would like to pull each of these IP addresses and ports and store them in a file jmsendpoints.properties... then load them dynamically. Something like this:

@ActivationConfigProperty(
    propertyName = "connectionParameters", 
    propertyValue = jmsEndpointsProperties.getConnectionParameters()),
public class TestMDB implements MessageDrivenBean, MessageListener

Is there a way to do that?

解决方案

No. The annotation processor (the annotation-based framework you're using) needs to implement an approach to handling placeholders.


As an example, a similar technique is implemented in Spring

@Value("#{systemProperties.dbName}")

Here Spring implements an approach to parsing that particular syntax, which in this case translates to something similar to System.getProperty("dbName");

这篇关于将动态参数传递给注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆