Tag: beaninfo

如何获得成员variables的注释?

我想知道一个类的某些成员variables的注释,我使用BeanInfo beanInfo = Introspector.getBeanInfo(User.class)来内省一个类,并使用BeanInfo.getPropertyDescriptors()来查找特定的属性,并使用Class type = propertyDescriptor.getPropertyType()来获得属性的类。 但我不知道如何获得注释添加到成员variables? 我尝试了type.getAnnotations()和type.getDeclaredAnnotations() ,但都返回类的注释,而不是我想要的。 例如 : class User { @Id private Long id; @Column(name="ADDRESS_ID") private Address address; // getters , setters } @Entity @Table(name = "Address") @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) class Address { … } 我想获得地址的注释:@Column,而不是类Address的注释(@Entity,@Table,@Cache)。 如何实现它? 谢谢。