*
The moose likes Spring and the fly likes Reading files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Reading files" Watch "Reading files" New topic
Author

Reading files

chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 800

Hi all, I have an xls file which has few records in it. There is a link which requests all the records in the file. I am planning to write a repository class which reads and loads the xls file. A service layer which sorts the list. In the controller I want to annotate a method with @PostConstruct which will make the service call and the service will call the repository to load and read the entire file. Whenever a request comes to the controller the list is returned. I will cache the method in the controller also. Is this a good approach?

Or should I load and read the file on the first request to the controller and then cache the result?

Can anyone please tell me how to proceed?

Thank you, good day.


Love all, trust a few, do wrong to none.
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1648
    
    7

I would look at Springs Resource abstraction. Have a look at the reference documentation

http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/resources.html
http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/resources.html#resources-as-dependencies


[How To Ask Questions][Read before you PM me]
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 800

I injected a resource like thisIn my repository class I used thisIs this a right approach to load a resource?

However I am not going to use a @PostConstruct because if there is some problem reading the file I will get errors during the server startup which might make the application unavailable (404 error).
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1648
    
    7

Your not going to get an exception until you try and access the resource in some way. Wherever you do this you can choose to catch and handle the exceptions.

After looking at this again you can probably just do something like below. It still uses the resource abstraction to read the file in but there is probably not anything to be gained by @Autowiring in the Resource, since you are most likely going to want to access it in some special format (you are probably using some library for reading an XLS)

In this example I am just using a String but gives you the idea.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading files
 
Similar Threads
Starting OCMJD
No shutdown hook?
URLyBird GUI start up how to get all Rooms?
Certain Points to ponder
NX:Client crashed cause deadlock in LockManager