Reputation: 116
I have a bean A, with a property pA. Now, i want to inject this property into another bean B's property pB. Tried using @Value, with both $ and #, but its not working. This is my class B.
@Component
public class B
{
@Value("${a.aP}")
private boolean bP;
}
Class A looks like below:
@Component
public class A
{
private boolean aP;
if(some condition){
aP = true;
}
}
Upvotes: 1
Views: 567
Reputation: 2245
You can inject bean A to B and then use @PostConstruct to set bP:
@Component
public class B {
private boolean bP;
@Autowired
private A a;
@PostConstruct
public void postConstructMenthod() {
bP = a.getAP();
}
}
Upvotes: 2