getBeansOfType() function not working?

797 views
Skip to first unread message

James

unread,
Dec 20, 2017, 1:03:18 PM12/20/17
to xnat_discussion
Has anyone used XDAT.getContextService().getBeansOfType(MyBean.class) in XNAT 1.7?

I'm Autowiring a bean within a plugin class and trying to access that bean inside the XNAT application. 

Some Example code below.
I'm able to get a beanA by name and by type, but getting ALL beans of type MyBean does not work.


// Plugin Code //

@Component("beanA")
public class BeanA implements myBean{
  // some stuff
}

@Autowired
MyBean beanA;


// XNAT Application code //

public interface MyBean{
  // some stuff 
}

// This doesn't work, returns an empty Map.
XDAT.getContextService().getBeansOfType(MyBean.class);

// This works fine
XDAT.getContextService().getBean("beanA");

// This also works fine
XDAT.getContextService().getBean(MyBean.class);

Herrick, Rick

unread,
Jan 4, 2018, 10:56:03 AM1/4/18
to xnat_di...@googlegroups.com

It looks like the issue is that the application context that’s getting set for the context service is not the full application context? I’m not sure what’s going on there. That service has always been a bit hinky and is, in the bluntest terms, a complete and total hack to give non-Spring code access to objects in the Spring context. I’ll try to play with it some later and see if I can figure out what’s going on with it.

 

-- 

Rick Herrick

Sr. Programmer/Analyst

Neuroinformatics Research Group

Washington University School of Medicine

Phone: +1 (314) 273-1645

--
You received this message because you are subscribed to the Google Groups "xnat_discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xnat_discussi...@googlegroups.com.
To post to this group, send email to xnat_di...@googlegroups.com.
Visit this group at https://groups.google.com/group/xnat_discussion.
For more options, visit https://groups.google.com/d/optout.

 


The materials in this message are private and may contain Protected Healthcare Information or other information of a sensitive nature. If you are not the intended recipient, be advised that any unauthorized use, disclosure, copying or the taking of any action in reliance on the contents of this information is strictly prohibited. If you have received this email in error, please immediately notify the sender via telephone or return mail.

McKay, Mike

unread,
Jan 4, 2018, 5:45:49 PM1/4/18
to xnat_discussion

I am also not sure what is going on, but I wanted to chime in to say that I encountered a similar issue. I was trying to do XDAT.getContextService().getBeansOfType(OrmStrategy.class) to get a list of OrmStrategies for managing PACS. I was able to work around it well enough for what I was working on at the time, but I will want to have getBeansOfType working before I release a more general purpose DICOM query/retrieve plugin I am developing.


Thanks for letting us know that this is an issue others are having as well. Hopefully this is something that is easy for us to fix!


-Mike


Sent: Wednesday, December 20, 2017 12:03:18 PM
To: xnat_discussion

Subject: [XNAT Discussion] getBeansOfType() function not working?
--
You received this message because you are subscribed to the Google Groups "xnat_discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xnat_discussi...@googlegroups.com.
To post to this group, send email to xnat_di...@googlegroups.com.
Visit this group at https://groups.google.com/group/xnat_discussion.
For more options, visit https://groups.google.com/d/optout.

ka...@radiologics.com

unread,
Dec 6, 2018, 5:25:52 PM12/6/18
to xnat_discussion
I looked into this a bit, and I learned that the difference between getBean and getBeansOfType is that the former also include beans in ancestor factories. The solution is to use BeanFactoryUtils’s beansOfTypeIncludingAncestors instead of getBeansOfType. I added this method to the ContextService (https://bitbucket.org/radiologics_kate/framework/commits/5ac7b961a9badb1c5b08e9e55733ef6d46959cb8), but I don't have permission to submit a PR. 

McKay, Mike

unread,
Dec 7, 2018, 10:58:00 AM12/7/18
to xnat_discussion

We already have a (slightly different) fix for this bug in the code that will go out with our next release.


https://bitbucket.org/xnatdev/framework/commits/4c30e1de8213833037f3d57fe5f0590b538fcaaa


-Mike


From: xnat_di...@googlegroups.com <xnat_di...@googlegroups.com> on behalf of ka...@radiologics.com <ka...@radiologics.com>
Sent: Thursday, December 6, 2018 4:07:40 PM
To: xnat_discussion
Subject: Re: [XNAT Discussion] getBeansOfType() function not working?
 

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages