【发布时间】:2017-01-27 03:43:40
【问题描述】:
假设我有 A、B、C 类,其中 B 类包含 setter 和 getter。 我想在 A 类(通过设置 true 对 B 类执行 Setter 操作)和 C 类(在 B 类上执行 getter 操作)中使用 B 类。 但是我面临的问题是,如果对同一个 B 类对象执行 get,则应该在 C 类中打印 true,而不是打印 false。 sn-p如下
Class A {
@Inject
B b;
//Setting true
b.set(true);
}
Class B {
boolean b;
//Setter
//Getter
}
Class C {
@Inject
B b;
//
boolean ball=b.get();
Log.info(ball) //False is getting printed instead of true why is this!!
}
【问题讨论】:
-
如何创建注入的
b?通过一些代码或配置文件?你如何设置b为真?请阅读How to create a Minimal, Complete, and Verifiable example。 -
它是一个 CDI bean,我们不使用配置文件,它只是依赖注入。我使用 setter 方法将 b 设置为 true
标签: java spring jakarta-ee dependency-injection cdi