I'm not claiming this is the best solution (it's sleazy), but if your
problem is getting this information out of spring without having access
to the spring context, you could use an old-style singleton. Configure
your bean in spring and make its no-arg constructor set the static
reference to the singleton. The you can use MyPojo.getInstance() to get
a handle to the singleton that spring has configured.
As a more general solution, I usually have a singleton lying around with
a reference to my application context so I can get the context when I'm
not in a servlet.
-Steve
Karl M. Davis wrote:
I'm not a Spring guy myself but writing files to an
application-relative path doesn't sound like a great idea: what if
you're application isn't exploded/unpacked (i.e. what if everything is
running from a WAR/JAR)?
Why not load a writable path for the application from
System.getProperty("myapp.fileStore"), using a Preferences instance,
or something along those lines?
Best regards,
Karl
----- Original Message -----
From: "Steven Elliott" <elli...@interactivetec.com>
To: jug-discussion@tucson-jug.org
Sent: Wednesday, February 11, 2009 2:24:38 PM GMT -07:00 U.S. Mountain
Time (Arizona)
Subject: [jug-discussion] Spring directory path
Sorry for posting this here but I am pretty sure someone has the
answer that seems to elude me.
I have a POJO that contains application specific constants. One of
the constants I want to put there is the file system root path of the
application so that I can write files relative to the root from other
POJOs. I want to do this in a generic way so the field in the POJO I
would want to be either a string or a File (in otherwords I don’t want
to use a Resource which binds me to Spring).
Normally I would do this through servletContext.getRealPath(“/”) but
the POJO is not a Servlet and has no access to ServletContext.
What is the best practice of doing this the IOC Spring (2.0) way?
Thanks for the help.
Steven
---------------------------------------------------------------------
To unsubscribe, e-mail: jug-discussion-unsubscr...@tucson-jug.org
For additional commands, e-mail: jug-discussion-h...@tucson-jug.org