0

I am autowiring an object in a component. I was able to access it in one component and I am unable to access it in another component.

Why is that?

    @Component
    public class AcListenerPublisherImpl implements MessageListener {

        private static final Logger log = Logger.getLogger(AcListenerSubscriber.class);

        @Value("${ac.templates.actual}")
        private String actual;

        @Value("${ac.templates.curve}")
        private String curve;

        @Autowired
        private AcImpl ac;

        public AcListenerPublisherImpl(){

        }

        @Override
        public void onMessage(Message message) {

            try {
                ......
            } catch (JMSException | ClassNotFoundException | IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

        }

        private void executeevent(AcTransactionRecord record) {
            AcEvent acEvent;
LINE 100            log.info("Got port" +ac.getServer().getHttpPort() + "got actual"+ actual);
            acEvent = new AcEventPublisherImpl(ac, actual.split(","), curve.split(","), record);


        }

I cant access ac object, it is throwing a null pointer exception at that line 100. Important thing is, same object is autowired in another already existing class and it works perfectly fine. It is in the new class that I created here where I am not able to access any of those autowired objects. I cant access the values with $ sign too. These all worked perfectly in other classes. Could this be due to the package structure? or I am doing anything wrong?

africandrogba
  • 334
  • 1
  • 3
  • 21
  • You haven't showed us any reason to believe that `ac.server` isn't null. – chrylis -cautiouslyoptimistic- Sep 18 '17 at 16:53
  • I cant access the $ symbol values also. ac.server is not the problem. I cant access the instance variables. They are all null. – africandrogba Sep 18 '17 at 17:47
  • I think as pointed, I created this class through new keyword. Now I am using autowire keyword. That solves it. Important thing is when values are null always check how you are creating an object of it. I didnt check that. I didnt even realize I should check. – africandrogba Sep 18 '17 at 19:57

0 Answers0