• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem accessing @Autowired object from another reference

 
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have 2 classes
1) ScheduledTasks.java
2) UserNotificationServiceImpl.java

I have @Autowired a class in both the above classes.

I have set a Set<String> private member variable in ScheduledTasks into the @Autowired reference(userDao) whcih I later want to access later from UserNotificationDAO of UserNotificationServiceImpl.
But I am not able to.

Firstly I thought, may be spring boot is not creating a singleton instance.
I printed the object. I assume, that it prints the memory address by default if toString method is not overriden.

I found both the memory address to be the same.

I set a Set<String> in ScheduledTasks into userDao and which I can see that it has been properly set in ScheduedTasks itself before I proceeded.

You can have a look at the logs




*************Inside ScheduledTasks.java ***********************************
Notification: *** Inside sendNotificationForOrdersOnHold()
Notification: *** Executing Query as select oos2.orderitemnumber||','||oon2.event_id ORDER_EVENT from om_order_notifications1 oon2, om_order_stage oos2  where (oon2.orderitemnumber, oon2.user_notification_date) in (SELECT oon.orderitemnumber, MAX(oon.user_notification_date) FROM om_order_notifications1 oon, om_order_stage oos WHERE oon.orderitemnumber = oos.orderitemnumber  AND UPPER(oos.orderstagestatus) LIKE('%HOLD%') AND oos.stage_flag = 'Y' AND oon.NOTIFICATION_ID='14' GROUP BY oon.orderitemnumber HAVING MAX(oon.user_notification_date) + (select nvl(min(VALUE),30) from OM_MASTER_DATA WHERE KEY='on_hold_day_span') < sysdate AND MIN(oon.user_notification_date) + (select nvl(min(VALUE),365) from OM_MASTER_DATA WHERE KEY='when_to_cancel_order') > sysdate)  and oon2.ORDERITEMNUMBER=oos2.ORDERITEMNUMBER  and oos2.stage_flag='Y'  AND oon2.NOTIFICATION_ID='14' and oon2.event_id like '%1006'
Notification: *** Orders to be notified = [160304995,20160624.10598.1006]
Notification: *** userDAO in ScheduledTasks = net.colt.notifications.DAO.impl.UserNotificationDAOImpl@72061775

//         userDao.setOrdersOnHold(ordersOnHold);
Notification: *** Orders On Hold set in UserDAO = [160304995]


********* Inside UserNotificationServiceImpl ***************************
Here I have @Autowired UserNotificationDAO and when I invoke getOrdersOnHold, I get an empty Set.

Notification: *** ###################################### userNotificationDAO.getOrdersOnHold=[]
Notification: *** UserNotificationDAO in UserNotificationServiceImpl = net.colt.notifications.DAO.impl.UserNotificationDAOImpl@72061775


Both the objects are same.

But I do not get the set, when I try to access it using the other reference. (As you can see getOrdersOnHold gives me an empty Set.

Any help in this regard is appreciated.

Regards
Yogesh
 
The happiness of your life depends upon the quality of your thoughts -Marcus Aurelius ... think about this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic