• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading files

 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic