whats the correct project structure for a spring mvc project

I am making a spring mvc project.
Although i generated the initial project structure by selecting a sample project from maven archetypes. I am assuming eveything is fine with it. Just wanted to conform with experts if my project structure looks fine.
I am attaching snapshot within my intellij idea project structure. Attaching 2 images as couldnt capture everything in one shot.
Any thoughts and commnets on it will be really helpful for me .

Rohit BajajAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
Yeah, in general it looks fine. The only possible issue I have is with your "utils/meta.json" file. Do you realise that at the moment, that file WON'T get packaged in with the rest of the application. If you deployed this using Maven, it would build a .war file that you could drop in an application server but then you would also have to separately supply the meta.json file in an appropriate location for your code to pick it up.

If you DO want it to be part of your application, it would go somewhere under the src/main/resources directory. And then you may need to tweak the code that you already have that reads the file to locate it via a classpath rather than a regular old file system path.

On that, is there any reason why you don't keep the info that is in that file in your MySQL database?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rohit BajajAuthor Commented:
oh i didnt know it wont get packaged inside war. So i think adding some resources tag in pom.xml might may make maven include in war. otherwise i will put them under resources.
Also generally there is a folder called utils in a project where should be the location of this ?

No there is no particular reason why the data is stored in a file rather than in mysql database.
Will it be better if i stored it in a database ?
mccarlIT Business Systems Analyst / Software DeveloperCommented:
No, it is a resource, just like your .properties and .xml files, so just put it somewhere under src/main/resources. Now for the change that you need to make to your code. In your controller (or hopefully by now, you have moved it out to a separate class) you had a couple of lines like this...

            byte[] jsonData = Files.readAllBytes(Paths.get("utils/meta.json"));
            JsonNode rootNode = objectMapper.readTree(jsonData);

Open in new window

Now, assuming that the file is located at src/main/resources/utils/meta.json, you can change the code above to this...

            InputStream jsonStream = getClass().getResourceAsStream("/utils/meta.json");
            JsonNode rootNode = objectMapper.readTree(jsonStream);

Open in new window

However, if it were me, I would store this info in the database. It just means that if you need to change/add/delete any of that information in the future, you can do that easily by updating the database, rather than updating the meta.json file on every machine that you have deployed to.

The argument against using a database would be if you were NOT already doing DB stuff and so you had to add extra libraries and create a database just for this information. But in your case, you are already communicating with the DB and you already have other data in there, so it should be trivial to add this config data too. Note that in this case, while you would still have a DAO to interface to this data in the DB, you would probably set up some sort of caching so that you weren't pulling this data from the DB on every request. You may even only need to do it once when your app starts up, potentially.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.