注入“@PropertyInject”字段时,要检查注入的值
When "@PropertyInject" fields are injected, want to check injected values
我在 类 中使用 @PropertyInject
。
那些 类 是通过蓝图注入的(使用 maven 蓝图插件)。我想用 @PropertyInject
.
检查注入字段的值
问题是在 PostConstruct
中(由 maven-blueprint-plugin -> init 方法支持)所有字段仍然为空。
但是,如果我使用注入这些字段的对象(骆驼端点),则所有字段都已正确设置。
因此在 "PostConstruct" 和实例的使用之间,所有字段都被注入。有没有一种方法可以在注入后直接挂钩以检查值 (!=null)?
将@PropertyInject 放在setter 上并检查setter 中设置的值。
@PropertyInject("prop")
public void setProp(String value) {
if (value == null) {
throw new IllegalArgumentException("prop cannot be null");
}
this.prop = value;
}
我在 类 中使用 @PropertyInject
。
那些 类 是通过蓝图注入的(使用 maven 蓝图插件)。我想用 @PropertyInject
.
问题是在 PostConstruct
中(由 maven-blueprint-plugin -> init 方法支持)所有字段仍然为空。
但是,如果我使用注入这些字段的对象(骆驼端点),则所有字段都已正确设置。
因此在 "PostConstruct" 和实例的使用之间,所有字段都被注入。有没有一种方法可以在注入后直接挂钩以检查值 (!=null)?
将@PropertyInject 放在setter 上并检查setter 中设置的值。
@PropertyInject("prop")
public void setProp(String value) {
if (value == null) {
throw new IllegalArgumentException("prop cannot be null");
}
this.prop = value;
}