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

2022/6/3 1:21:36

本文主要是介绍无法在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>

 



这篇关于无法在Java 11中使用@PostConstruct和@PostDestroy的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程