A key element of Spring is infrastructural support at the application level: Spring focuses on the 'plumbing' of enterprise applications so that teams can focus on application-level business logic, without unnecessary ties to specific deployment environments. In this tutorial, we will take the previous Gradle + Spring MVC XML example, rewrite it to support @JavaConfig annotation configuration, no more XML files. P.S This example will works in Servlet 3.0+ container only, like Tomcat 7 or Jetty 9. Spring MVC - Environment Setup - This chapter will guide us on how to prepare a development environment to start your work with the Spring Framework. (IDE) like Borland JBuilder, Eclipse, IntelliJ IDEA or Sun ONE Studio, then compile and run a simple program to confirm that the IDE knows where Java is installed, otherwise do proper setup as. To use Spring in your project, you need the Spring facet that comprises libraries and UI elements for configuring settings specific to Spring. IntelliJ IDEA automatically detects Spring configuration files in your code. The IDE will inform you if the project requires any adjustements and suggest the necessary actions.
Creating a basic Spring MVC project was a difficult thing for beginners because it involves so many steps from configuring all spring dependencies to deploying into some server. But once Spring Tool Suite introduced, creating a Spring MVC application has become a very simple process. In this post we are going to see how to create Spring MVC application using Spring Tool Suite within a minute.
Before going to start first let me tell you what are all the Pre-requisite software or jars which is required to develop the Spring MVC.
- Spring Tool Suite IDE 3.7.2 (Based on Eclipse Mars.1 (4.5.1)) – Download here
- Spring 4.1.1 – Maven is sufficient, no download is required.
- JDK 1.8 – Download from here
How to Create Spring MVC Application using Java Configuration
First Create a New Project.
How to use xampp server. In some of the STS IDE, we can able to select Spring Project directly. If your STS are not having an option then got with this approach. Select Spring Legacy Project from the menu.
Once you select and click on next we will see a window to select Spring MVC Project. At the top we are required to give project name and click next. I have given as STSSpringMVCHelloWorld.
Followed by that we will get a window to give high level package name.
That’s it. We will get a project like this.
Spring Mvc Intellij Idea
In some times we will get a project with errors. To avoid those errors, update the project using maven by following the below image. Right click the project, go to Maven and Update Project.
Once you click Update Project, we will get a window to select the project to Update. Also make sure Force Update of Snapshots/Releases checkbox is unchecked.
This STS bundled with Tomcat 7 and Tomcat 8, so by default we could see Server window in the STS Eclipse (See below Image). So we just have to add the project and start the server. That’s it.
How to add Project to the Server
Follow the below steps and add a Project to the Server which is bundled with STS.
Right click the Server and Click on Add and Remove.
Spring Mvc Intellij Idea Tutorial
We will see a window like this. Add our project and click on “Finish” and start the server. That’s it.
Spring Mvc Ide Eclipse
Open the browser and hit the URL as below.
I have added my message in HomeController.java and displayed it in home.jsp
We will see in detail about all the files in our next tutorials blogs. This How to Create Spring MVC application using Spring Tool Suite is available in my repository also, to download please click the link below.