|
From: <jue...@we...> - 2003-05-05 11:26:20
|
Hi Chris,
You're right, this can easily lead to confustion on Unix platforms. We =
need a more convenient solution.
I don't want to introduce yet another config parameter, so I've applied =
a more general change. From the beginning, I've planned to support plain =
absolute file paths as a convenience, not as a major feature. Given the =
current problematic interpretation of file paths, I've removed =
AbstractApplicationContext's absolute file path support altogether, =
replacing the getResourceByRelativePath template method with =
getResourceByPath.
This means that an ApplicationContext implementation can interpret any =
non-URL path any way it wants, not just relative file paths. =
AbstractApplicationContext's default implementation treats it as =
(absolute or relative) file path now, XmlWebApplicationContext generally =
as ServletContext resource (no matter if relative or not), =
ClassPathApplicationContext as classpath resource (always interpreting =
as root path, not relative to the class).
Note that absolute file paths can still be accessed easily by using a =
URL like "file://C:/test/test.dat", so we don't lose that capability. I =
consider this clean and convenient, sacrificing non-URL absolute file =
path support isn't a hassle at all. Is that appropriate for your =
requirements too?
Regards,
Juergen
-----Original Message-----
From: Chris Smith [mailto:ch...@lo...]
Sent: Monday, May 05, 2003 11:33 AM
To: j=FCrgen h=F6ller [werk3AT]
Subject: Re: [Springframework-developer] spring-web broken on unix
Hi J=FCrgen,
I thought about suggesting using relative paths by default, but that=20
leads to a confusing situation where absolute paths are looked up in the =
file system and relative paths are looked up in the servlet context. =20
Not to mention the fact that an absolute path on one OS can be=20
considered a relative path on another. And I don't like removing the=20
leading "/" from "/WEB-INF" as there will be plenty of people who=20
include it and end up tearing their hair out when Spring reports it=20
can't find a file that patently exists (like I did yesterday!).
What I was going to suggest in my original email is that we have an=20
explicit param that states where a config location should be loaded =
from:
<web-app>
<context-param>
<param-name>configLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<context-param>
<param-name>configLocationType</param-name>
<param-value>servletcontext</param-value>
</context-param>
...
configLocationType could have the values "servletcontext" or=20
"filesystem". "servletcontext" should be the default for a web app=20
context loader, so you could omit it from the above example. This way,=20
you can control where files are loaded from explicitly, regardless of=20
whether they are relative or absolute.
So, that's what I was going to suggest yesterday, but I wasn't sure=20
whether servlets had the same restrictions as EJBs on accessing the file =
system. I'm sure I read it somewhere but still can't find it in the=20
servlet spec, so I guess it's ok. (If it wasn't allowed, the solution=20
would be straightforward - always load from the servlet context).
I'm happy to code this up if you like, but you'd have to commit it.
Regards,
Chris
j=FCrgen h=F6ller [werk3AT] wrote:
>Hi Chris, Spring web users,
>
>Thanks for the report! Admittedly, I only testet this on Windows and =
didn't think about Unix path names (should have come to my mind, =
though). I've changed the default paths =
("/WEB-INF/applicationContext.xml", =
"/WEB-INF/<servlet-name>-servlet.xml") to clear relative paths now, =
omitting the leading slash.
>
>On the occasion, I've made config lookup more flexible, allowing not =
only for a servlet context init param "configLocation" for the root =
context, but also "configLocationPrefix" and "configLocationSuffix" for =
namespaced contexts (defaults are "WEB-INF/" and ".xml").
>
>Note that the trailing "-servlet" comes from the FrameworkServlet's =
namespace handling and is thus part of the namespace. To override the =
namespace for a specific servlet, just set a servlet init parameter =
"namespace" to the desired value.
>
>Default initialization should still behave like before, and often you =
won't need any customization. But if you like to, you can now customize =
config lookup like this:
>
><web-app>
> <context-param>
> <param-name>configLocationPrefix</param-name>
> <param-value>WEB-INF/myControllers/</param-value>
> </context-param>
> <context-param>
> <param-name>configLocation</param-name>
> <param-value>WEB-INF/myRoot.xml</param-value>
> </context-param>
> <listener>
> =
<listener-class>com.interface21.web.context.ContextLoaderListener</listen=
er-class>
> </listener>
> <servlet>
> <servlet-name>test</servlet-name>
> =
<servlet-class>com.interface21.web.servlet.ControllerServlet</servlet-cla=
ss>
> <init-param>
> <param-name>namespace</param-name>
> <param-value>myTest</param-value>
> </init-param>
> <load-on-startup>3</load-on-startup>
> </servlet>
></web-app>
>
>This should look up the root context file in "WEB-INF/myRoot.xml", and =
the ControllerServlet context file in =
"WEB-INF/myControllers/myTest.xml".
>
>Regards,
>Juergen
>
>
>-----Original Message-----
>From: Chris Smith [mailto:ch...@lo...]
>Sent: Sunday, May 04, 2003 3:02 PM
>To: spr...@li...
>Subject: [Springframework-developer] spring-web broken on unix
>
>
>Hi everyone,
>
>Juergen, I've just found a problem with the changes you made to=20
>XmlWebApplicationContext recently.
>
>When loading the bean config in getInputStreamForBeanFactory(), it=20
>delegates to the base class AbstractApplicationContext's=20
>getResourceAsStream() method. For a config location such as=20
>"/WEB-INF/test-servlet.xml", that method will try to load it using a=20
>URL, fail, catch the MalformedURLException, then see if the path is=20
>relative or absolute. If relative, it loads it using the overridden=20
>getResourceByRelativePath().
>
>That all works fine on windows, but on unix, =
"/WEB-INF/test-servlet.xml"=20
>is considered an absolute path because it starts with a slash. The=20
>context fails to load because it tries to load it as a File rather than =
>from the servlet context.
>
>The problem is that we can't tell whether a config location like=20
>"/WEB-INF/test-servlet.xml" is a path to a file or a resource in the=20
>servlet context. I couldn't find it in a brief flick through the=20
>servlet spec, but I didn't think servlets were allowed to access=20
>resources outside the servlet container. If that's the case, then=20
>XmlWebApplicationContext ought to override getResourceAsStream() with =
an=20
>implementation that always loads from the servlet context.
>
>Regards,
>
>Chris
>
>
>
>-------------------------------------------------------
>This sf.net email is sponsored by:ThinkGeek
>Welcome to geek heaven.
>http://thinkgeek.com/sf
>_______________________________________________
>Springframework-developer mailing list
>Spr...@li...
>https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
>
>-------------------------------------------------------
>This sf.net email is sponsored by:ThinkGeek
>Welcome to geek heaven.
>http://thinkgeek.com/sf
>_______________________________________________
>Springframework-developer mailing list
>Spr...@li...
>https://lists.sourceforge.net/lists/listinfo/springframework-developer
> =20
>
|