Getting System Variables / Environment information using spring ??

Posted on 2005-04-21
Last Modified: 2010-03-31

InitialContext ic = new InitialContext();

                  String rootDirectory = (String)ic.lookup("java:comp/env/rootDirectory");
                  String pathSeparator = (String)ic.lookup("java:comp/env/pathSeparator");

These can get you the system pathseperator and rootDirectory information using any J2EE Compliant container....

How to acheive the same using spring ??

Question by:letsbedecent
    1 Comment
    LVL 15

    Accepted Solution

    Isn’t that defeating the philosophy of IoC container.
    Jndi elements under java:comp/env are local variable to the specific J2EE item.
    I think in the spring world you are suppose to do that by having a property on the bean and let spring initialize it for you.
      <bean id="your_bean_id" class="full_class_name">
        <property name="otherBeanRef">
            <ref bean="a reference to another bean via that bean id"/>
      <property name="pathSeparator">
              <value><![CDATA[/]]></value> <!—any constant value &#61664;
     <property name="rootDirectory">
              <value><![CDATA[/home/xxx/]]></value> <!—any constant value &#61664;

    where your bean should have setters/getters for pathSeparator and rootDirectory

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    sumHeights2  challenge 7 51
    Fibonacci challenge 11 61
    strCopies  challenge 17 60
    mapAB Challlenge 35 52
    If you have upgraded to Java2 update 10 on a Microsoft Windows client, you may have discovered that your Java application does not work as it did before.  For example, the colors of your Java2D graphic may be all wrong for no apparent reason. Aft…
    Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
    Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
    This video teaches viewers about errors in exception handling.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now