Announcement Announcement Module
Collapse
No announcement yet.
How should I configure a global variabel Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How should I configure a global variabel

    I would like to configure global variable identifying my application. I would like to do this in a matter where changing it is just a matter of changing a configuration file, leaving the way it's retrieved in code unchanged.

    I'd like to access this Id in my interceptor/filter framework code, and I would prefer not to inject values into the interceptor/filter.

    A static getter would be preferable, but then I won't be able to inject the application id using Spring.

    So, do anyone have a suggestion on how to best do this?
    Last edited by magott; Jul 16th, 2007, 08:50 AM. Reason: spelling

  • #2
    U can try using singleton class on spring :

    this some example :

    MyService :

    Code:
    package net.sf.hrs.services.impl;
    
    public class MyService
    {
        private static MyService instance;
    
        private String applicationName;
    
        public void setApplicationName(String applicationName)
        {
            this.applicationName = applicationName;
        }
    
        public String getApplicationName()
        {
            return applicationName;
        }
    
        public static MyService getInstance()
        {
            if (instance == null) instance = new MyService();
            return instance;
        }
    }
    applicationContext :

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    
    <beans>
        <bean id="test" class="net.sf.hrs.services.impl.MyService" factory-method="getInstance">
            <property name="applicationName" value="test"/>
        </bean>
    </beans>
    Your application code :

    Code:
    public class HelloWorld
    {
       public void write()
       {
           MyService.getInstance().getApplicationName();  
       }
    }
    Hope this can help u

    Comment

    Working...
    X