-1

I have to develop one desktop base application(it has no request/response) and it has many classes. my Main/Controller class read (*.properties) file, like

allExtensions = properties.getProperty("ReportFileExtension");

and i have mention some file extension in .properties file like ReportFileExtensionn = .pdf,.doc etc. This key read from .properties file in Main class and i want use this key value in other class without passing argument in any method or constructor.

is it spring provide a local storage ? so i can use to store attribute and use it other class.

Thanks in Advc.

Gabu
  • 83
  • 1
  • 13
  • Not sure what is the local storage you're referring to. But I'll suggest you refer to this [link](http://stackoverflow.com/questions/9259819/how-to-read-values-from-properties-file) to import the properties and use it for all classes that needs to – Samuel Kok Sep 06 '16 at 08:02
  • Local storage means we can say that one kind of session which access whole application, it is use to store attribute in storage and retrieve attribute from storage and use it. that's it. – Gabu Sep 06 '16 at 08:07
  • Do you mean reading values in Spring from a file like in this: http://stackoverflow.com/a/11312178/5502924 ? – Fr333du Sep 06 '16 at 09:04
  • No simply i want to store attribute in one file and get this attribute to other file without using HttpRequest,HttpSession even no argument pass call. – Gabu Sep 06 '16 at 09:18
  • Eh? Spring is a server-side Web framework. It has nothing to do with desktop applications whatsoever. – user207421 Sep 06 '16 at 09:44

1 Answers1

0

Your question is bit confusing but based on comments I think you are struggling to understand how to get keys from properties.

Check PropertiesLoaderUtils

Resource resource = new ClassPathResource("/my.properties");
Properties props = PropertiesLoaderUtils.loadProperties(resource);

Now iterate over the props object

Try this

public Set<Object> getAllKeys(){
        Set<Object> keys = prop.keySet();
        return keys;
    }

Or this

public void printProperties() {
        for(Entry<Object, Object> e : props.entrySet()) {
            System.out.println(e);
        }
    }

Properties are available globally but if you want you can create a static map and cache the properties in it.

Sheetal Mohan Sharma
  • 2,908
  • 1
  • 23
  • 24
  • i wan't use properties file to store data and retrieve it.i want to store data like in memory so when i need it i will get in memory and use it. – Gabu Dec 07 '16 at 06:25
  • 1
    Ideally you should not rely on in memory databases for prod apps as its not reliable. Ideally they are used for unit testing only, but you insist then you can use in memory DB - H2 or HSQL or Derby. Spring provides support for them . Refer docs here or link given next . http://docs.spring.io/spring/docs/3.0.0.M4/reference/html/ch12s08.html or http://suryakand-shinde.blogspot.co.uk/2013/02/working-with-spring-embedded-database.html – Sheetal Mohan Sharma Dec 07 '16 at 15:06