@PostConstruct of abstract ancestors are not invoked

后端 未结 2 1248
温柔的废话
温柔的废话 2021-01-13 12:53

I\'m writing a JAX-RS library (not an application).

I have:

abstract class A {

    @PostConstruct
    priva         


        
2条回答
  •  别那么骄傲
    2021-01-13 13:13

    Annotations are not inherited. You must create a @PostConstruct annotated method for each sub-class.

    To assist/remind the developer, you could require a postConstruct() method and hope the developer annotates it appropriately as suggested by its name:

    public abstract class A {
    
        @PostConstruct // annotation here has no value except as a reminder
        public abstract void postConstruct();  
    

提交回复
热议问题