0

consider the following code:

public abstract class MachineInPitImpl extends AbstractPersistentObject implements MachineInPit {

 protected PersonReference currentOperatorRef;
 public void setCurrentOperatorRef(PersonReference currentOperatorRef) {
    this.currentOperatorRef = currentOperatorRef;
    this.currentOperatorObj = null;
}
public PersonReference getCurrentOperatorRef() {
    return currentOperatorRef;
}

The above class is not wired with spring context, I need to extend this class and grab the values in the get method of this class in my new class. I have wrote a class as this:

public class MachineOPJMXBeanImpl extends MachineInPitImpl {
public MachineOPJMXBeanImpl(){

}

@Override
public PersonReference getCurrentOperatorRef() {
    return super.getCurrentOperatorRef();
}
}

But the value in this class get method is null.Why am I getting null value? Here is the applicationcontext.xml file:

<bean id="machineOPJMXBean"
      class="com.mincom.works.cc.personnel.node.MachineOPJMXBeanImpl" parent="machineInPitImpl">
    <property name="currentOperatorRef" ref="currentOperatorRef"/>

</bean>

<bean id="machineInPitImpl" class="minestar.pitlink.domain.pitmodel.MachineInPitImpl" abstract="true" scope="singleton" lazy-init="true">
    <property name="currentOperatorRef" ref="currentOperatorRef"/>


</bean>

<bean id="currentOperatorRef" class="minestar.machinetracking.domain.PersonReference"/>
lifeat stake
  • 65
  • 1
  • 9
  • Show the code where you're calling `getCurrentOperatorRef`. – chrylis -cautiouslyoptimistic- Oct 22 '14 at 06:18
  • @chrylis The `getCurrentOperatorref` is called in `machineinpitimpl` class which is shown above. I have debugged this class and checked the values is there in this method. But when I call from `MachineOPJMXBeanimpl` class with super word its giving null value. – lifeat stake Oct 22 '14 at 06:29
  • Where's the *client* code that's calling it? – chrylis -cautiouslyoptimistic- Oct 22 '14 at 06:32
  • @chrylis The full code I cannot manage to paste chrylis for security reasons. Just assume that the value is there in `machineinpitimpl` . – lifeat stake Oct 22 '14 at 06:39
  • Then there's not enough information to help you, though I recommend you look here for one possible issue: http://stackoverflow.com/questions/19896870/why-is-my-spring-autowired-field-null – chrylis -cautiouslyoptimistic- Oct 22 '14 at 06:40
  • Is minestar.machinetracking.domain.PersonReference a BeanFactory? – Andrés Oviedo Oct 22 '14 at 08:36
  • @andresoviedo It is a java class. – lifeat stake Oct 22 '14 at 08:50
  • @chrylis Hi, I think when my spring xml instantiates the `machineinpitimpl` class it running only the init method which is in the default constructor. How can I have a another constructor so that it instantiates the whole class? – lifeat stake Oct 22 '14 at 09:04
  • @lifeatstake Seeing your example, the injection should be working fine. Can you send the piece of code where you are instantiating the context and getting your "machineOPJMXBean" bean? – Andrés Oviedo Oct 22 '14 at 09:13
  • @andresoviedo Check my comment to chrylis. Can this be a reason. And the xml code is pasted above. Do you need something more? – lifeat stake Oct 22 '14 at 09:19
  • @lifeatstake Are you getting your bean like "appContext.getBean("machineOPJMXBean"); – Andrés Oviedo Oct 22 '14 at 09:39
  • @andresoviedo No. It's a 13 gb code. The code to get the bean is wired previously. – lifeat stake Oct 22 '14 at 09:42
  • @lifeatstake My suspicion is that your "machineOPJMXBean" is not being constructed by Spring. Can't help more without more info. I would suggest to isolate your test in a JUnit and verify that property is being injected correctly. – Andrés Oviedo Oct 22 '14 at 09:51
  • @andresoviedo What does this do then: ` ` – lifeat stake Oct 22 '14 at 10:01
  • @chrylis How will I instantiate a named constructor. The constructor is like this `public MachineInPitImpl(MachineInPitImpl mip){//here are the attributes initialised}` . How will I give this constructor as constructor-args in spring. – lifeat stake Oct 22 '14 at 10:39

0 Answers0