Results 1 to 3 of 3

Thread: Required annotation and bean inheritance

  1. #1
    Join Date
    Jan 2010
    Posts
    2

    Default Required annotation and bean inheritance

    Hi,

    I have two bean classes Parent and Child, where Child extends Parent. Parent has a field -- parentField -- with a public getter/setter marked as @Required. In the spring config xml a Child bean is defined. The @Required annotation, however, is not enforced if parentField is not set. I have tried defining an abstract bean in the config xml for the Parent class and specifying it as the parent of the Child bean, but this does not work either. @Required enforces things properly for fields defined within the Child class. Does anyone know whether this is supposed to be supported? I can work around it fine by checking in a @PostConstruct method.

    Thanks in advance..
    Jerry

  2. #2
    Join Date
    May 2007
    Posts
    157

    Default

    @Required by design is not @Inherited. See more info on annotation inheritance in this blog.

  3. #3
    Join Date
    Jan 2010
    Posts
    2

    Default

    Thanks a lot for pointing this out. I was now able to achieve the result by creating a custom annotation marked as @Inherited and configuring the RequiredAnnotationBeanPostProcessor as follows:

    <bean class="org.springframework.beans.factory.annotatio n.RequiredAnnotationBeanPostProcessor">
    <property name="requiredAnnotationType" value="com.test.Mandatory"/>
    </bean>

    Thanks,
    Jerry

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •