java - 将动态参数传递给注释?

标签 java annotations

我正在使用以下注释:

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

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

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

有办法吗?

最佳答案

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


例如,在 Spring 中实现了类似的技术。

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

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

的内容

关于java - 将动态参数传递给注释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12568385/

相关文章:

java - 对格式不正确的 XML 进行 XPath 评估?

java - 如果我想使用单个 UIMA 依赖库,是否需要重写整个 java 项目?

java.lang.ClassCastException : oracle. sql.BLOB 无法转换为 oracle.sql.BLOB

java - 如何在复合键中使用生成的值?

java - 强制具有特定注释的方法具有特定参数/签名

java - 在 Java 上限制上传速度?

java - 无法使用 driver.close() 关闭窗口

android - android @TargetApi注解是什么意思

java - 识别 Java 注释处理器中类型的稳定性

java - 运行时类路径中是否需要注解类文件?