Skip to content
Advertisement

@PostConstruct and @PreDestroy annotations do not work

I have TennisCoach class:

JavaScript

And such main class:

JavaScript

Expected output is:

Inside default constructor

Inside postconstructor

DailyFortune

Practice your backhand volley

Inside predestroyer

But I get this:

Inside default constructor

DailyFortune

Practice your backhand volley

It seems like @PostContruct and @PreDestroy annotations do not work correctly. I cannot find the reason of my problem.

Advertisement

Answer

If you use java 9+ then add dependency javax.annotation:javax.annotation-api (or use java 8).

Or use spring-boot 2 if you using spring-boot 1.

Advertisement