gpt4 book ai didi

java - Spring @Required 注解已弃用?

转载 作者:行者123 更新时间:2023-12-03 08:18:58 24 4
gpt4 key购买 nike

我正在尝试向我的 bean 添加 @Required 注释,但编译器表示它已被弃用。

public class Product {
private String id;

public String getId() {
return id;
}

@Required
public void setId(String id) {
this.id = id;
}
}

是否有不同的注释?

最佳答案

阅读documentation :

Deprecated as of 5.1, in favor of using constructor injection for required settings (or a custom InitializingBean implementation).

public class Product {
private String id;

public Product(String id) {
this.id = id;
}

public String getId() {
return id;
}

关于java - Spring @Required 注解已弃用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68398867/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com