How to test constructor of a class that has a @PostConstruct method using Spring?

后端 未结 4 2146
遇见更好的自我
遇见更好的自我 2021-02-18 13:12

If I have a class with a @PostConstruct method, how can I test its constructor and thus its @PostConstruct method using JUnit and Spring? I can\'t simply use new ClassName(param

4条回答
  •  故里飘歌
    2021-02-18 13:38

    By default, Spring will not aware of the @PostConstruct and @PreDestroy annotation. To enable it, you have to either register ‘CommonAnnotationBeanPostProcessor‘ or specify the ‘‘ in bean configuration file.

    or

提交回复
热议问题