1
votes

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;

}

}
1
How are these instantiated / obtained. Are they both managed by Spring or are you using the new() keyword anywhere to create one. - cowls
Both are spring managed beans. - Amith

1 Answers

2
votes

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();
   }
}