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

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

问题描述

我用下面的注释:

  @Activati​​onConfigProperty(
    propertyName的=connectionParameters
    为PropertyValue =主机= 127.0.0.1,端口= 5445,主机= 127.0.0.1,端口= 6600),
公共类TestMDB实现消息驱动Bean,消息监听

我想拉这些IP地址和端口,并将它们存储在一个文件中 jmsendpoints.properties ...然后动态地加载它们。事情是这样的:

  @Activati​​onConfigProperty(
    propertyName的=connectionParameters
    的PropertyValue = jmsEndpointsProperties.getConnectionParameters()),
公共类TestMDB实现消息驱动Bean,消息监听

有没有办法做到这一点?


解决方案

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


作为一个例子,一个类似的技术在<一个实施href=\"http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/\"><$c$c>Spring

  @Value(#{systemProperties.dbName})

下面<一个href=\"http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/ex$p$pssions.html\"><$c$c>Spring实现了一个方法的解析<​​/ em>的特定语法,在这种情况下,转换为类似的东西,以 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天全站免登陆