无法在Java 11中使用@PostConstruct和@PostDestroy

我无法在Java 11中使用@PostConstruct和@PostDestroy

我在项目中使用@PostConstruct@PostDestroy注释时遇到问题。我不能使用这些注释,尽管我导入了Java的注释,但这些注释似乎并不存在请注意,

@PostConstruct@PreDestroy注释都是Java EE的一部分。而且由于Java EE在Java9中已被弃用,而在Java 11中已被删除,因此我们必须添加一个附加依赖项才能使用这些注释:

 

需要在网址 https://mvnrepository.com/artifact/javax.annotation/javax.annotation-api  中加入依赖, 如

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

 

posted @ 2022-06-02 18:18  study_php_java_C++  阅读(248)  评论(0编辑  收藏  举报