我有一个 ejb-jar.xml,其中包含我的一个 MDB 的配置信息。
里面有一个配置:
<activation-config-property>
<activation-config-property-name>addressList</activation-config-property-name>
<activation-config-property-value>mq://test.server.uk:7676</activation-config-property-value>
</activation-config-property>
当我的项目被构建和打包然后分发给用户时,我需要能够确保这个值可以被修改,因为用户有不同的服务器地址。
目前我可以选择在属性文件中设置地址。无论如何,我可以在 glassfish 4.0 上部署期间使用属性值修改此 xml 吗?
如果不是,我每次有人想要应用程序并重新构建它时都必须设置值吗?
我愿意将配置放在我只需要动态的地方,以便用户可以在属性文件中设置服务器地址。
最佳答案
您可以尝试的一件事是使用 @AroundConstruct
拦截器在运行时设置 MDB 上的值。值得注意的是,虽然可以在您的 ejb-jar.xml 中使用占位符,但它主要依赖于容器,并且明显缺乏有关如何为 Glassfish 完成此操作的阅读 Material ,这应该是您担心的根源。让我们试试这个:
@MessageDriven
@Interceptors(AddressListInterceptor.class)
public class YourMDB
public class AddressListInterceptor {
@AroundConstruct
private void begin(InvocationContext iCtxt) {
/**load your property prior to this point */
ActivationConfigProperty addressList = new ActivationConfigProperty{
public String propertyName(){
return "addressList";
}
public String propertyValue(){
return theAddressList;
}
public Class<? extends Annotation> annotationType(){
return ActivationConfigProperty.class;
}
};
try {
/**get the annotations, with the intention of adding yours (addressList) to the array using the method demonstrated in
http://stackoverflow.com/a/14276270/1530938 */
Annotations[] annotations = iCtxt.getClass().getAnnotations();
iCtxt.proceed(); //this will allow processing to continue as normal
} catch (Exception ex) {
}
}
除了不幸需要自己扫描和修改注解之外,这种方法给您带来的好处是,您可以在 bean 实例化之前进入 MDB 的生命周期并修改注解的值。当 bean 投入使用时,它将采用您设置的值,并且一切都应该井井有条
关于jakarta-ee - 在 GlassFish 4.0 中部署期间修改 ejb-jar.xml 的配置属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35063954/