Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Environment Variables in Spring?

Hybrid View

  1. #1
    Join Date
    Mar 2005
    Location
    Madrid, Spain
    Posts
    71

    Default Environment Variables in Spring?

    I would like to know how to access to an environment variable in Spring. For example I would like to use some environment variable in order to set the url property:

    Code:
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
          <property name="driverClassName"><value>org.hsqldb.jdbcDriver</value></property> 
          <property name="url"> 
            <value>jdbc&#58;hsqldb&#58;P&#58;/springapp/v6/springapp/db/test</value> 
          </property> 
        </bean>
    but I don't know which environment variables are accepted by Spring configuration files and how to use them (syntax), for example: ${user.home}, $HOME, etc. Any way are there any Spring Environment variables, could be used on the Spring configuration files.

    Thanks in advance,

    David Leal

  2. #2
    Join Date
    Nov 2004
    Location
    Hilversum - The Netherlands
    Posts
    1,054

    Default

    Take a look at the:
    http://www.springframework.org/docs/...onfigurer.html

    and
    http://www.springframework.org/docs/...postprocessors


    Btw:
    it would be nice if I could evaluate some expressions in Spring (maybe by using something like ognl), so I can say:

    <property name="timeout" value="ognl:60*60*24"/>

    and even something like:

    <property name="timeout" value="ognl:60*60*${hours}*fooBean.days"/>

  3. #3
    Join Date
    Mar 2005
    Location
    Madrid, Spain
    Posts
    71

    Default

    Thanks Alarmnummer,

    I am going to take a detailed look to this information, but I am afraid that
    I am asking about somethink different.

    What I like is to have access to some System Environment Variables. For example to refer one of the following system variables that shows the set dos command:

    Code:
    c&#58;\> set
    
    ALLUSERSPROFILE=C&#58;\Documents and Settings\All Users
    ANT_HOME=c&#58;\archiv~1\Java\Apache\Ant\ant
    APPDATA=C&#58;\Documents and Settings\david\Datos de programa
    APR_ICONV_PATH=C&#58;\Archivos de programa\Subversion\iconv
    CLASSPATH=.;S&#58;\java\class;S&#58;\java\lib;S&#58;\java\resources
    CommonProgramFiles=C&#58;\Archivos de programa\Archivos comunes
    COMPUTERNAME=BOSTON4BDRCHA
    ComSpec=C&#58;\WINDOWS\system32\cmd.exe
    FP_NO_HOST_CHECK=NO
    HOMEDRIVE=C&#58;
    HOMEPATH=\Documents and Settings\david
    JAVA_HOME=C&#58;\Java\j2sdk\j2sdk1.4.2_08
    LOGONSERVER=\\BOSTON4BDRCHA
    MuPAD_SWP_200=C&#58;\Archivos de programa\swp40\MuPAD
    MY_CLASSPATH=S&#58;\java\class;S&#58;\java\lib;S&#58;\java\resources
    MY_PATH=c&#58;\archiv~1\Java\Apache\Ant\ant\bin;c&#58;\archiv~1\cvs;C&#58;\Java\j2sdk\bin
    NUMBER_OF_PROCESSORS=1
    OS=Windows_NT
    Path=c&#58;\archiv~1\MiKTeX\Main\miktex\bin;c&#58;\archiv~1\Java\Apache\Ant\ant\bin;c&#58;\archiv~1\cvs;C&#58;\Java\j2sdk\bin;C&#58;\WINDOWS\system32;C&#58;\WINDOWS;C&#58;\WINDOWS\System32\Wbem;C&#58;\ARCHIV~1\ULTRAE~1;c&#58;\archiv~1\matlab6p5\bin\win32;c&#58;\archiv~1\Subversion\bin
    PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
    PROCESSOR_ARCHITECTURE=x86
    PROCESSOR_IDENTIFIER=x86 Family 6 Model 9 Stepping 5, GenuineIntel
    PROCESSOR_LEVEL=6
    PROCESSOR_REVISION=0905
    ProgramFiles=C&#58;\Archivos de programa
    PROMPT=$P$G
    SESSIONNAME=Console
    SystemDrive=C&#58;
    SystemRoot=C&#58;\WINDOWS
    TEMP=C&#58;\DOCUME~1\david\CONFIG~1\Temp
    TMP=C&#58;\DOCUME~1\david\CONFIG~1\Temp
    USERDOMAIN=BOSTON4BDRCHA
    USERNAME=david
    USERPROFILE=C&#58;\Documents and Settings\david
    windir=C&#58;\WINDOWS
    What about if I want to use the system environment variable HOMEPATH on the myapp-servlet.xml. Is there any way to get a reference to this variable?

    Thanks in adavance,

    David

  4. #4
    Join Date
    Nov 2004
    Location
    Hilversum - The Netherlands
    Posts
    1,054

    Default

    Quote Originally Posted by dleal
    Thanks Alarmnummer,

    I am going to take a detailed look to this information, but I am afraid that
    I am asking about somethink different.

    What I like is to have access to some System Environment Variables.
    I think that is going to be complicated, see topics at:
    http://www.google.nl/search?hl=nl&q=...e+zoeken&meta=

    It seems there is no good way in Java to access them.

    Btw:
    you can access the system.properties with the links I have given you.

  5. #5
    Join Date
    Aug 2004
    Location
    u.s.a
    Posts
    399

    Default

    I believe PropertyPlaceHo.... accesses the environment system properties too.

    "....A configurer will also check against system properties (e.g. "user.dir") if it cannot resolve a placeholder with any of the specified properties. This can be customized via "systemPropertiesMode". "

  6. #6
    Join Date
    Nov 2004
    Location
    Hilversum - The Netherlands
    Posts
    1,054

    Default

    Quote Originally Posted by jbetancourt
    I believe PropertyPlaceHo.... accesses the environment system properties too.

    "....A configurer will also check against system properties (e.g. "user.dir") if it cannot resolve a placeholder with any of the specified properties. This can be customized via "systemPropertiesMode". "
    Yes.. but the question is if you can access the environmental variables. And I don`t think this is going to be easy: check the google link.

  7. #7
    Join Date
    Aug 2004
    Location
    u.s.a
    Posts
    399

    Default

    The google links are addressing getEnv(), which is deprecated. However, the javadoc for System.getProperty(String key), seems to still be recommended.

    And, Spring uses that: propVal = System.getProperty(placeholder);

    Of course, there are many issues with Java accessing system level stuff, but that is is where other languages really shine like Perl, Python, etc.

  8. #8
    Join Date
    Nov 2004
    Location
    Hilversum - The Netherlands
    Posts
    1,054

    Default

    Quote Originally Posted by jbetancourt
    The google links are addressing getEnv(), which is deprecated. However, the javadoc for System.getProperty(String key), seems to still be recommended.
    Yes.. but the question is: can you find the environmental variables in the System.properties.

  9. #9
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    No, System.getProperty will not return environment variables. System.getEnv will (which isn't deprecated in 1.5).

  10. #10
    Join Date
    Aug 2004
    Location
    u.s.a
    Posts
    399

    Default

    I just looked at both 1.4 and 1.5 api docs. System does have many differences, one of these is that getenv is not deprecated in 1.5. Fun.

Similar Threads

  1. Spring MVC Web Framework versus Struts
    By biguniverse in forum Web Flow
    Replies: 27
    Last Post: Aug 29th, 2012, 03:57 AM
  2. Environment Variables in Spring?
    By dleal in forum Data
    Replies: 4
    Last Post: Aug 9th, 2005, 04:58 PM
  3. Replies: 0
    Last Post: Mar 8th, 2005, 10:00 PM
  4. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM
  5. spring in a clustered environment
    By kshacks in forum Container
    Replies: 1
    Last Post: Sep 29th, 2004, 07:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •