-
Jan 13th, 2010, 11:52 AM
#1
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
-
Jan 13th, 2010, 06:31 PM
#2
@Required by design is not @Inherited. See more info on annotation inheritance in this blog.
-
Jan 14th, 2010, 08:29 AM
#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
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
-
Forum Rules