I can't use @PostConstruct and @PostDestroy with Java 11

后端 未结 2 370
一个人的身影
一个人的身影 2020-12-30 02:45

I\'ve got problem with using @PostConstruct and@PostDestroy annotations in my project. I can\'t use these annotations and it looks like these doesn

相关标签:
2条回答
  • 2020-12-30 03:16

    Note that both @PostConstruct and @PreDestroy annotations are part of Java EE. And since Java EE has been deprecated in Java 9 and removed in Java 11 we have to add an additional dependency to use these annotations:

    For Maven

    <dependency>
        <groupId>javax.annotation</groupId>
        <artifactId>javax.annotation-api</artifactId>
        <version>1.3.2</version>
    </dependency>
    

    If using Gradle

    implementation "javax.annotation:javax.annotation-api:1.3.2"
    

    Found here: https://www.baeldung.com/spring-postconstruct-predestroy

    0 讨论(0)
  • 2020-12-30 03:21

    You have only spring-webmvc, you need the rest of the spring to be able to use their annotations. Probably spring-core and spring-annotations.

    0 讨论(0)
提交回复
热议问题