zl程序教程

您现在的位置是:首页 >  后端

当前栏目

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

JAVA 无法 11 使用 PostConstruct
2023-09-27 14:21:27 时间

我无法在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>