You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Chris Hostetter <ho...@fucit.org> on 2009/06/19 02:48:34 UTC

Re: Solr spring application context error

: Date: Fri, 08 May 2009 08:27:58 -0400
: From: Mark Miller
: Subject: Re: Solr spring application context error
: 
: I've run into this in the past as well. Its fairly annoying. Anyone know why
: the limitation? Why aren't we passing the ClassLoader thats loading Solr
: classes as the parent to the lib dir plugin classloader?

FWIW: We do.  

I'm not sure what exactly the problem might have been in this thread 
(class loaders are nightmares, and spring doesn't make life any easier 
unless *everything* involved is using spring) but SolrResourceLoader uses 
Thread.currentThread().getContextClassLoader() to set the parent class 
loader unless an explict parent class loader was specified. (the webapp 
loader is the parent for the solr shardLib loader, which is the parent for 
the individual core loaders)

at least ... that's the way it use to work, and skimming the code it 
doesn't look like it's been broken (in an obvious way)

-Hoss


Re: Solr spring application context error

Posted by John Wang <jo...@gmail.com>.
Ah, my bad, this is the same as null. Sorry for the stupid comment.
-John

On Thu, Jul 9, 2009 at 1:55 PM, John Wang <jo...@gmail.com> wrote:

> Hi guys:
>      Could it be in method:load in class CoreContainer:
>
> libLoader = SolrResourceLoader.createClassLoader(f, null);
>
>
>    The parent ClassLoader is set to null, shouldn't it be the current
> classloader? e.g."
>
>
> libLoader =
> SolrResourceLoader.createClassLoader(f,Thread.currentThread().getContextClassLoader(
> ));
>
>
> Thanks
>
>
> -John
>
> On Sun, Jul 5, 2009 at 11:38 PM, John Wang <jo...@gmail.com> wrote:
>
>> Hi Chris:
>>
>>      The problem is that (at least for me, not a expert spring'er) The
>> beans are being loaded (and when the class loading issue occurs) at
>> construction time of FileSystemXmlApplicationContex, the setClassLoader
>> method by the time can be called is too late.
>>
>> -John
>>
>>
>> On Thu, Jul 2, 2009 at 2:26 PM, Chris Hostetter <hossman_lucene@fucit.org
>> > wrote:
>>
>>>
>>> :     I did try that. The problem is that you can't tell
>>> : FileSystemXmlApplicationContext to load with a different ClassLoader.
>>>
>>> why not?
>>>
>>> it subclasses DefaultResourceLoader which has the  setClassLoader method
>>> Mark pointed out.
>>>
>>>
>>>
>>> -Hoss
>>>
>>>
>>
>

Re: Solr spring application context error

Posted by Mark Miller <ma...@gmail.com>.
A value of null will cause the parent class loader to be set to:

Thread.currentThread().getContextClassLoader();

The context class loader for a given thread is the class loader that the 
threads creator wants you to use (good for servlet containers),
so looks right to me. If its not set, it will use the parent thread's 
class loader.

- Mark

John Wang wrote:
> Hi guys:
>      Could it be in method:load in class CoreContainer:
>
> libLoader = SolrResourceLoader.createClassLoader(f, null);
>
>
>    The parent ClassLoader is set to null, shouldn't it be the current
> classloader? e.g."
>
>
> libLoader =
> SolrResourceLoader.createClassLoader(f,Thread.currentThread().getContextClassLoader(
> ));
>
>
> Thanks
>
>
> -John
>
> On Sun, Jul 5, 2009 at 11:38 PM, John Wang <jo...@gmail.com> wrote:
>
>   
>> Hi Chris:
>>
>>      The problem is that (at least for me, not a expert spring'er) The
>> beans are being loaded (and when the class loading issue occurs) at
>> construction time of FileSystemXmlApplicationContex, the setClassLoader
>> method by the time can be called is too late.
>>
>> -John
>>
>>
>> On Thu, Jul 2, 2009 at 2:26 PM, Chris Hostetter <ho...@fucit.org>wrote:
>>
>>     
>>> :     I did try that. The problem is that you can't tell
>>> : FileSystemXmlApplicationContext to load with a different ClassLoader.
>>>
>>> why not?
>>>
>>> it subclasses DefaultResourceLoader which has the  setClassLoader method
>>> Mark pointed out.
>>>
>>>
>>>
>>> -Hoss
>>>
>>>
>>>       
>
>   


-- 
- Mark

http://www.lucidimagination.com




Re: Solr spring application context error

Posted by John Wang <jo...@gmail.com>.
Hi guys:
     Could it be in method:load in class CoreContainer:

libLoader = SolrResourceLoader.createClassLoader(f, null);


   The parent ClassLoader is set to null, shouldn't it be the current
classloader? e.g."


libLoader =
SolrResourceLoader.createClassLoader(f,Thread.currentThread().getContextClassLoader(
));


Thanks


-John

On Sun, Jul 5, 2009 at 11:38 PM, John Wang <jo...@gmail.com> wrote:

> Hi Chris:
>
>      The problem is that (at least for me, not a expert spring'er) The
> beans are being loaded (and when the class loading issue occurs) at
> construction time of FileSystemXmlApplicationContex, the setClassLoader
> method by the time can be called is too late.
>
> -John
>
>
> On Thu, Jul 2, 2009 at 2:26 PM, Chris Hostetter <ho...@fucit.org>wrote:
>
>>
>> :     I did try that. The problem is that you can't tell
>> : FileSystemXmlApplicationContext to load with a different ClassLoader.
>>
>> why not?
>>
>> it subclasses DefaultResourceLoader which has the  setClassLoader method
>> Mark pointed out.
>>
>>
>>
>> -Hoss
>>
>>
>

Re: Solr spring application context error

Posted by John Wang <jo...@gmail.com>.
Hi Chris:

     The problem is that (at least for me, not a expert spring'er) The beans
are being loaded (and when the class loading issue occurs) at construction
time of FileSystemXmlApplicationContex, the setClassLoader method by the
time can be called is too late.

-John

On Thu, Jul 2, 2009 at 2:26 PM, Chris Hostetter <ho...@fucit.org>wrote:

>
> :     I did try that. The problem is that you can't tell
> : FileSystemXmlApplicationContext to load with a different ClassLoader.
>
> why not?
>
> it subclasses DefaultResourceLoader which has the  setClassLoader method
> Mark pointed out.
>
>
>
> -Hoss
>
>

Re: Solr spring application context error

Posted by Chris Hostetter <ho...@fucit.org>.
:     I did try that. The problem is that you can't tell
: FileSystemXmlApplicationContext to load with a different ClassLoader.

why not?  

it subclasses DefaultResourceLoader which has the  setClassLoader method 
Mark pointed out.



-Hoss


Re: Solr spring application context error

Posted by John Wang <jo...@gmail.com>.
Hi Mark:

    I did try that. The problem is that you can't tell
FileSystemXmlApplicationContext to load with a different ClassLoader.

-John

On Wed, Jul 1, 2009 at 4:20 PM, Mark Miller <ma...@gmail.com> wrote:

> I havn't done much a spring in a while, and I've never done anything
> hardcore, but could you:
>
> in your plugin code, grab the classloader of the plugin class and init the
> spring context with it?
>
> org.springframework.core.io.DefaultResourceLoader#setClassLoader
>
> Or you could use the solr classloader to load the spring context?
>
> Or perhaps we could provide access to the classLoader from the core?
>
>
> --
> --
> - Mark
>
> http://www.lucidimagination.com
>
>
> On Wed, Jul 1, 2009 at 6:52 PM, John Wang <jo...@gmail.com> wrote:
>
> > Hi guys:
> >
> >    What is the plan with this issue? Should there be a bug created?
> >
> >    I am having a similar issue from a different angle:
> >
> > 1) using spring which is instantiating beans when the plugins are loaded
> > 2) classloader mismatch.
> > 3) only way to resolve, copy my jars to solr.war's WEB-INF/lib
> >
> > -John
> >
> > On Thu, Jun 18, 2009 at 6:53 PM, Mark Miller <ma...@gmail.com>
> > wrote:
> >
> > > Chris Hostetter wrote:
> > >
> > >> : Yeah, I actually looked at the code and saw that later. I was
> > forgetting
> > >> the
> > >> : issue that bugged me (and confusing it with the trouble this guy was
> > >> having) -
> > >> : which is that plugins in the solr/lib folder cannot load from other
> > jars
> > >> in
> > >> : that folder. I think that was the actual issue.
> > >>
> > >> WTF?!? ... seriously?
> > >> I don't think i've ever tried it, but if that's really true then it
> > seems
> > >> like it must be a bug in URLClassLoader ... we're iterating over the
> > file
> > >> list to generate a URL[] before calling URLClassLoader.newInstance.
> > >>
> > >>
> > >> -Hoss
> > >>
> > >>
> > >>
> > > I have a fairly strong memory that its true - but its been almost a
> year
> > > now. I'll check when I get a chance. I also seem to remember mentioning
> > it
> > > to Erik and him already knowing of it...
> > >
> > > Or my mind is playing tricks on me. I'll check.
> > >
> > >
> > > --
> > > - Mark
> > >
> > > http://www.lucidimagination.com
> > >
> > >
> > >
> > >
> >
>

Re: Solr spring application context error

Posted by Mark Miller <ma...@gmail.com>.
I havn't done much a spring in a while, and I've never done anything
hardcore, but could you:

in your plugin code, grab the classloader of the plugin class and init the
spring context with it?

org.springframework.core.io.DefaultResourceLoader#setClassLoader

Or you could use the solr classloader to load the spring context?

Or perhaps we could provide access to the classLoader from the core?


-- 
-- 
- Mark

http://www.lucidimagination.com


On Wed, Jul 1, 2009 at 6:52 PM, John Wang <jo...@gmail.com> wrote:

> Hi guys:
>
>    What is the plan with this issue? Should there be a bug created?
>
>    I am having a similar issue from a different angle:
>
> 1) using spring which is instantiating beans when the plugins are loaded
> 2) classloader mismatch.
> 3) only way to resolve, copy my jars to solr.war's WEB-INF/lib
>
> -John
>
> On Thu, Jun 18, 2009 at 6:53 PM, Mark Miller <ma...@gmail.com>
> wrote:
>
> > Chris Hostetter wrote:
> >
> >> : Yeah, I actually looked at the code and saw that later. I was
> forgetting
> >> the
> >> : issue that bugged me (and confusing it with the trouble this guy was
> >> having) -
> >> : which is that plugins in the solr/lib folder cannot load from other
> jars
> >> in
> >> : that folder. I think that was the actual issue.
> >>
> >> WTF?!? ... seriously?
> >> I don't think i've ever tried it, but if that's really true then it
> seems
> >> like it must be a bug in URLClassLoader ... we're iterating over the
> file
> >> list to generate a URL[] before calling URLClassLoader.newInstance.
> >>
> >>
> >> -Hoss
> >>
> >>
> >>
> > I have a fairly strong memory that its true - but its been almost a year
> > now. I'll check when I get a chance. I also seem to remember mentioning
> it
> > to Erik and him already knowing of it...
> >
> > Or my mind is playing tricks on me. I'll check.
> >
> >
> > --
> > - Mark
> >
> > http://www.lucidimagination.com
> >
> >
> >
> >
>

Re: Solr spring application context error

Posted by John Wang <jo...@gmail.com>.
Hi guys:

    What is the plan with this issue? Should there be a bug created?

    I am having a similar issue from a different angle:

1) using spring which is instantiating beans when the plugins are loaded
2) classloader mismatch.
3) only way to resolve, copy my jars to solr.war's WEB-INF/lib

-John

On Thu, Jun 18, 2009 at 6:53 PM, Mark Miller <ma...@gmail.com> wrote:

> Chris Hostetter wrote:
>
>> : Yeah, I actually looked at the code and saw that later. I was forgetting
>> the
>> : issue that bugged me (and confusing it with the trouble this guy was
>> having) -
>> : which is that plugins in the solr/lib folder cannot load from other jars
>> in
>> : that folder. I think that was the actual issue.
>>
>> WTF?!? ... seriously?
>> I don't think i've ever tried it, but if that's really true then it seems
>> like it must be a bug in URLClassLoader ... we're iterating over the file
>> list to generate a URL[] before calling URLClassLoader.newInstance.
>>
>>
>> -Hoss
>>
>>
>>
> I have a fairly strong memory that its true - but its been almost a year
> now. I'll check when I get a chance. I also seem to remember mentioning it
> to Erik and him already knowing of it...
>
> Or my mind is playing tricks on me. I'll check.
>
>
> --
> - Mark
>
> http://www.lucidimagination.com
>
>
>
>

Re: Solr spring application context error

Posted by Mark Miller <ma...@gmail.com>.
Chris Hostetter wrote:
> : Yeah, I actually looked at the code and saw that later. I was forgetting the
> : issue that bugged me (and confusing it with the trouble this guy was having) -
> : which is that plugins in the solr/lib folder cannot load from other jars in
> : that folder. I think that was the actual issue.
>
> WTF?!? ... seriously?  
>
> I don't think i've ever tried it, but if that's really true then it seems 
> like it must be a bug in URLClassLoader ... we're iterating over the file 
> list to generate a URL[] before calling URLClassLoader.newInstance.
>
>
> -Hoss
>
>   
I have a fairly strong memory that its true - but its been almost a year 
now. I'll check when I get a chance. I also seem to remember mentioning 
it to Erik and him already knowing of it...

Or my mind is playing tricks on me. I'll check.

-- 
- Mark

http://www.lucidimagination.com




Re: Solr spring application context error

Posted by Chris Hostetter <ho...@fucit.org>.
: Yeah, I actually looked at the code and saw that later. I was forgetting the
: issue that bugged me (and confusing it with the trouble this guy was having) -
: which is that plugins in the solr/lib folder cannot load from other jars in
: that folder. I think that was the actual issue.

WTF?!? ... seriously?  

I don't think i've ever tried it, but if that's really true then it seems 
like it must be a bug in URLClassLoader ... we're iterating over the file 
list to generate a URL[] before calling URLClassLoader.newInstance.


-Hoss


Re: Solr spring application context error

Posted by Mark Miller <ma...@gmail.com>.
Chris Hostetter wrote:
> : Date: Fri, 08 May 2009 08:27:58 -0400
> : From: Mark Miller
> : Subject: Re: Solr spring application context error
> : 
> : I've run into this in the past as well. Its fairly annoying. Anyone know why
> : the limitation? Why aren't we passing the ClassLoader thats loading Solr
> : classes as the parent to the lib dir plugin classloader?
>
> FWIW: We do.  
>
> I'm not sure what exactly the problem might have been in this thread 
> (class loaders are nightmares, and spring doesn't make life any easier 
> unless *everything* involved is using spring) but SolrResourceLoader uses 
> Thread.currentThread().getContextClassLoader() to set the parent class 
> loader unless an explict parent class loader was specified. (the webapp 
> loader is the parent for the solr shardLib loader, which is the parent for 
> the individual core loaders)
>
> at least ... that's the way it use to work, and skimming the code it 
> doesn't look like it's been broken (in an obvious way)
>
> -Hoss
>
>   
Yeah, I actually looked at the code and saw that later. I was forgetting 
the issue that bugged me (and confusing it with the trouble this guy was 
having) - which is that plugins in the solr/lib folder cannot load from 
other jars in that folder. I think that was the actual issue.

- Mark

-- 
- Mark

http://www.lucidimagination.com