Announcement Announcement Module
Collapse
No announcement yet.
Required annotation and bean inheritance Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    @Required by design is not @Inherited. See more info on annotation inheritance in this blog.

    Comment


    • #3
      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

      Comment

      Working...
      X