简体   繁体   English

未加载抽象类中声明的注释

[英]Annotations declared in Abstract Class not being loaded

I have a Dynamic Web Project created in Eclipse (Juno) using Spring/Maven/Weblogic. 我有一个使用Spring / Maven / Weblogic在Eclipse(Juno)中创建的动态Web项目。 I also have an Abstract class into which I inject a property (on the setter) via a properties file. 我也有一个Abstract类,通过属性文件将属性(在setter上)注入其中。 The annotation used is @Value(value="${some.property}"). 使用的注释为@Value(value =“ $ {some.property}”)。
For some strange reason, when I deploy this project via maven to weblogic, the property gets injected for the concrete class that etends this Abstract class. 出于某些奇怪的原因,当我通过maven将该项目部署到weblogic时,将为扩展该Abstract类的具体类注入该属性。 But when I deploy this project directly onto weblogic via the Server -> Add Deployment, it fails to inject the property. 但是,当我通过服务器->添加部署将该项目直接部署到weblogic时,它无法注入该属性。 In fact it does inject properties for all other annotations on the concrete class but ignores any annotations for the abstract class. 实际上,它确实为具体类上的所有其他注释注入了属性,但忽略了抽象类的任何注释。 So basically this has nothing to do with coding but seems like some kind of config problem. 因此,基本上,这与编码无关,但看起来像某种配置问题。 Has anyone encountered something similar. 有没有人遇到过类似的事情。 Thanks. 谢谢。

public abstract class MyAbstract {
    @Value(value="${myproperty1}")
    public void setMyValue(String myValue) {
        log.debug("setMyValue({})", myValue);
        this.myValue = myValue;
    }
}

public class MyConcrete {
    @Value(value="${myproperty2}")
    public void setMyValue2(String myValue2) {
        log.debug("setMyValue2({})", myValue2);
        this.myValue2 = myValue2;
    }
}

I found the issue. 我发现了问题。 The thing is that this particular bean has @Scheduled annotation and hence does not qualify for Bean Post Processing. 关键是这个特定的bean具有@Scheduled注释,因此不符合Bean Post Processing的条件。 Since the properties via @Value are set during this phase, they are skipped. 由于通过@Value设置的属性是在此阶段设置的,因此将跳过它们。 Instead I shifted the bean creation into my application context xml file and set the properties from there eg. 相反,我将Bean创建转移到了我的应用程序上下文xml文件中,并从那里设置了属性。

<bean id="myConcrete" class="some.package.MyConcrete"
    p:value="${myproperty1}"
/>

Now the properties are getting injected during normal bean lifecycle ie after Instantiation but before Bean Post Processor. 现在,将在常规bean生命周期内(即,在实例化之后但在Bean Post Processor之前)注入属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM