|
From: <jue...@we...> - 2004-10-07 12:22:36
|
Well, Spring already has a ResourceLoader abstraction: Have a look at = the core.io package. When working at the BeanFactory level, resource loading is highly = configurable: You can pass in any Resource instance there, for example a = ClassPathResource with a specific ClassLoader. When working at the ApplicationContext level, each specific context = implementation defines a ResourceLoader for a concrete environment. It = is not really appropriate to pass in a custom ResourceLoader here, as = one of the points of a specific context is the assumption of a concrete = resource loading strategy. So I do recommend to subclass ClassPathXmlApplicationContext in case of = special needs when loading class path resources, overriding the = "getResource" method accordingly. However, it should not be necessary to subclass ClassPathResource = anymore: Since Spring 1.1.1, ClassPathResource has an explicit = constructor that takes a specific ClassLoader. (It also has one that = loads relative to a specific Class.) Another solution would be to simply set the current thread context class = loader via Thread.currentThread().setContextClassLoader(myClassLoader); , probably resetting it to null again afterwards. Juergen -----Original Message----- From: spr...@li... [mailto:spr...@li...]On Behalf Of Danilo Luiz Rheinheimer Sent: Thursday, October 07, 2004 2:23 PM To: spr...@li... Subject: Re: [Springframework-developer] Classloading Tran, Khiet wrote: > Hi, > > =20 > > I successfully experimented Spring, everything works fine. I am using=20 > the ClasspathXmlApplicationContext. > > Now I am integrating Spring within Eclipse RCP, which causes me some=20 > headaches: > > -My spring application cannot see the spring configuration = > file. I manage to solve this problem by subclassing the=20 > ClasspathXmlApplicationContext and ClasspathResource classes. Now=20 > Spring cannot see ResourceBundleMessageSource.class! > > =20 > > My question is then: how could I centralize all resource lookup or=20 > class lookup within Spring without subclassing all its classes. Spring = > uses the current Thread as its classloading mechanism, is there a way=20 > to change that globally? I want to define my way of class lookup = globally. > I do not have a solution to your problem. I am only sending this email to the Spring developers know I have the=20 same question. I already had post a message about this on the forums : http://forum.springframework.org/viewtopic.php?t=3D1089 I think the Spring components should access resouces using a interface = like this : public interface ResourceLoader { byte[] loadResource(String resourceName); } So any spring components with the need of acess resources will have a=20 setResourceLoader method and they will use a default implementation like = the current one. Maybe will be useful to set the default resource loader on the=20 ApplicationContext : ResourceLoader resourceLoader =3D new MyResourceLoaderImpl(); ClassPathXmlApplicationContext bf =3D new=20 ClassPathXmlApplicationContext(new String[] = {"/spring.xml"},resourceLoader); =20 It will be easy to implement things like chains of resurce loaders=20 to create the support to new protocols. I think this is a good idea. In Spring everything should be a=20 interface, so why not make this with the resource loader ? Danilo. ------------------------------------------------------- This SF.net email is sponsored by: IT Product Guide on ITManagersJournal Use IT products in your business? Tell us what you think of them. Give = us Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out = more http://productguide.itmanagersjournal.com/guidepromo.tmpl _______________________________________________ Springframework-developer mailing list Spr...@li... https://lists.sourceforge.net/lists/listinfo/springframework-developer |