You can refer to tutorialspoint link for a basic Spring Framework application development and deployment. Link for the same is below
https://www.tutorialspoint.com/spring/spring_mvc_hello_world_example.htm
The source code for the spring web application using IntelliJ is below
The Java package
package com.tutorialspoint;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.ui.ModelMap;
@Controller
@RequestMapping("/hello")
public class HelloController {
@RequestMapping(method = RequestMethod.GET)
public String printHello(ModelMap model) {
model.addAttribute("message", "Hello Spring MVC Framework!");
return "hello";
}
}
The web.xml which will be placed in the WEB-INF folder.
<web-app id="WebApp_ID" version="2.4"
xmlns="http://sun.com"
xmlns:xsi="http://w3.org"
xsi:schemaLocation="http://sun.com
http://sun.com/web-app_2_4.xsd">
<display-name>Spring MVC Application</display-name>
<servlet>
<servlet-name>web</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>web</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
web-servlet.xml will also be placed in the WEB-INF folder.
<beans xmlns="http://springframework.org"
xmlns:context="http://springframework.org"
xmlns:xsi="http://w3.org"
xsi:schemaLocation="
http://springframework.org
http://springframework.org/spring-beans-3.0.xsd
http://springframework.org
http://springframework.org/spring-context-3.0.xsd">
<context:component-scan base-package="com.tutorialspoint" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
The hello.jsp is placed in a jsp folder inside WEB-INF directory.
<%@ page contentType="text/html; charset=UTF-8" %>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h2>${message}</h2>
</body>
</html>
For a standard Maven web application, your directory tree in IntelliJ must look exactly like this:
my-spring-app/
└── src/
└── main/
├── java/
│ └── com/
│ └── tutorialspoint/
│ └── HelloController.java
└── webapp/
└── WEB-INF/
├── web.xml <-- Put here
├── web-servlet.xml <-- Put here
└── jsp/
└── hello.jsp
To run the application below are the steps
Running the Completed Application
- Compile the code and package the project as a
.war file via Maven. - Drop the compiled file into your local server deployment directory (such as Apache Tomcat).
- Access your running environment using the corresponding web layout path:
http://localhost:8080/hello
If WEB-INF is not visible inside inside your IntelliJ folder structure follow these steps
Step 1: Tell IntelliJ where your Web Resources live
- Press
Ctrl + Alt + Shift + S (Windows/Linux) or Cmd + ; (Mac) to open Project Structure. - Click Facets on the left panel.
- If you do not see a Web facet, click the
+ icon at the top, select Web, and choose your project module. - Look at the Web Resource Directories section at the bottom.
- If it is empty or wrong, click the
+ icon on the right side of that section. - Browse and select your
src/main/webapp folder, then click OK. - In the Deployment Descriptors section at the top, ensure your
web.xml path points correctly to .../src/main/webapp/WEB-INF/web.xml.
Step 2: Regenerate the Artifact
Now that the module knows where the web files are, recreate the artifact layout to force it to update:
- While still in the Project Structure window, click Artifacts on the left panel.
- Select your existing artifact and click the
- (Minus) icon at the top to delete it (don't worry, this won't delete your code). - Click the
+ (Plus) icon → Web Application: Exploded → From Modules... - Select your project module and click OK.
- Look at the Output Layout tab now. You should see your project name, and right under it, the
WEB-INF folder will automatically appear. - Click Apply and OK.
Step 3: Refresh and Run
- Go to the top menu and select Build → Rebuild Project.
- Run your Tomcat server again.
When doing the build if you get the below errors
Cannot compile module 'web' configured for JVM target 24: the JDK Oracle OpenJDK 17.0.18, currently associated with the module, does not support the required jvm target 24
Please add JDK 8 or later to Project Structure | Platform Settings | SDKs. The added JDK should support cross-compilation for JVM target 24. This JDK will be automatically picked by the IDE to compile for older JVM targets
This is because your project's Java Language Level (JVM target
24) is set higher than your Project JDK (Java 17). Java 17 cannot
compile code for Java 24.
To fix this, you must match your project settings in IntelliJ and your Maven configuration. [
1]
Fix 1: Change IntelliJ Project Settings to Java 17
- Press
Ctrl + Alt + Shift + S (Windows/Linux) or Cmd + ; (Mac) to open Project Structure. - Click Project on the left menu.
- Set SDK to
17 (Oracle OpenJDK 17.0.18). - Set Language level to
17 - Modules, local variable syntax for lambda parameters. [1]
- Click Modules on the left menu.
- Select your module named
web. - Click the Language level dropdown and set it to
17 (or Project default (17)). [1]
- Click Apply and OK.
Fix 2: Change IntelliJ Compiler Settings
- Press
Ctrl + Alt + S (Windows/Linux) or Cmd + , (Mac) to open Settings / Preferences. - Go to Build, Execution, Deployment → Compiler → Java Compiler.
- Look at the table under Per-module bytecode version.
- Find your module
web and change its Target bytecode version from 24 to 17. - Click Apply and OK.
Fix 3: Update your Maven pom.xml
Maven often overrides IntelliJ settings. Ensure your pom.xml explicitly targets Java 17. Open your pom.xml and add or modify the following properties inside the <project> tag:
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
Step 4: Rebuild the Project
Go to the top menu, select Build → Rebuild Project. The compilation error will disappear.
If you are still getting the error firstly make sure the pom.xml changes are persisted. Next
Clear IntelliJ's Target Bytecode Cache
IntelliJ heavily caches compiler targets. Let's force it to reset.
- Press
Ctrl + Alt + S (Windows/Linux) or Cmd + , (Mac) to open Settings. - Go to Build, Execution, Deployment → Compiler → Java Compiler.
- Look at the table under Per-module bytecode version.
- If your
web module is listed there, click on it and use the - (Minus) icon on the right side of the table to delete the row entirely. - Ensure the Project bytecode version dropdown at the very top of this same page is set to
17. - Click Apply and OK.
Refresh Maven Using the Right-Click Menu
Do not use the floating icon this time; we need a hard sync.
- On the left side of your screen, look at the Project tool window.
- Right-click on your root project folder (the main folder with your app name).
- Scroll down to Maven → click Reload Project.
- Wait for the sync progress bar at the bottom right of IntelliJ to completely finish.
3 quick methods to reload pom.xml
Method 1: The Floating Notification Icon (Fastest)
As soon as you make a change and save your pom.xml, a small, translucent floating Maven icon (a blue "M" with a circular arrow) appears in the top-right corner of your code editor tab.
- Click that floating icon to reload. [1]
Method 2: The Right-Click Project Menu
- Go to your Project Files Tree view on the left side of your screen.
- Right-click on your root project folder (the very top folder containing your application name).
- Scroll down and hover over Maven.
- Click Reload Project. [1]
Method 3: The Dedicated Maven Tool Window
- Look at the extreme right edge of your IntelliJ window frame.
- Click the vertical tab labeled Maven to slide open the Maven tool menu.
- Click the two circular arrows icon (the "Reload All Maven Projects" tool button) located at the very top-left corner of that small side panel.
If your IntellJ does not have a built in tomcat you can download tomcat from the tomcat apache site
https://tomcat.apache.org/download-11.cgi
Extract the zip folder to a path in your windows directory.
Set the TOMCAT_HOME environment variable to your tomcat installation path.
Add TOMCAT_HOME/bin to your PATH environment variable.
Now configure TOMCAT setting in IntelliJ as follows
Step 1: Open the Settings
- Click Edit on that popup prompt (or click the Tomcat dropdown in the top-right and select Edit Configurations...).
Step 2: Fix the Tomcat Application Server Path
- In the Server tab, look at the very top field labeled Application server.
- If it is empty or highlighted in red, click the Configure... button right next to it.
- Click the folder icon under Tomcat Home and browse to the exact folder on your computer where you downloaded and extracted Tomcat (e.g.,
C:\apache-tomcat-9.x or /Users/name/tomcat). - Click OK. The red highlight should disappear.
Step 3: Link the Web Artifact
- Switch to the Deployment tab (located next to the Server tab at the top of that window).
- Look at the box under Deploy at server startup. If it is completely empty, Tomcat doesn't know what code to run.
- Click the
+ (Plus) icon on the right side of that box and select Artifact.... - Choose the option that ends with
:war exploded and click OK. - Look at the Application context field at the bottom of this tab. Change whatever text is inside it to a single forward slash:
/ - Click Apply and then OK.
Step 4: Start the Server
Now, click that green Play (Run) icon in the top right corner again. The "configuration incorrect" error will be gone, and the server log window should start rolling at the bottom of IntelliJ.
After starting Tomcat if you get the error HTTP Status 404 – Not Found
This 404 Not Found error means your Tomcat server started up successfully, but it cannot match your browser URL to your Spring controller mapping. [
1]
Because your controller explicitly looks for the path @RequestMapping("/hello"), hitting a raw base URL will cause this error.
This can be resolved as below
1. Try the Full Precise URLs
In your browser address bar, try entering both variations exactly as written below:
- Variation A:
http://localhost:8080/hello - Variation B:
http://localhost:8080/web/hello
2. Confirm Your Tomcat Application Context
If neither of those works, your Tomcat setup might have an auto-generated context path. Let's make it simple:
- Click your Tomcat dropdown in the top right of IntelliJ and select Edit Configurations....
- Go to the Deployment tab.
- Look at the Application context text box at the very bottom.
- Delete whatever text is currently inside that box and replace it with a single forward slash:
/ - Click Apply and OK.
- Restart your Tomcat server using the red-and-green circular arrow icon in your log panel.
- Open your browser and go to exactly:
http://localhost:8080/hello
With these fixes and configurations I was able to run my Spring application from the web browser and I got the output as below
https://www.tutorialspoint.com/spring/spring_mvc_hello_world_example.htm
God's Word for the day
Three Depressing Things
At two things my heart is grieved
and because of a third anger comes over me
A warrior in want through poverty
Intelligent men who are treated contemptuously
And a man who turns back from righteousness to sin.
The Lord will prepare him for the sword
Sirach 26:28
Gospel teachings of Jesus
The parable of the unforgiving servant
"For the reason the kingdom of heaven may be compared
to a King who wished to settle accounts with his slaves.
When he began the reckoning one who owed him ten
thousand talents was brought to him, and as he could not
pay, hos Lord ordered him to be sold, together with his
wife and children and all his possessions, and payment
to be made. So the slave fell on his knees before him saying,
'Have patience with me, and I will pay you everything."
And out of pity for him, the Lord of the slave released him
and forgave him the debt. But that same slave, as he went out
came upon one of his fellow slaves who owed him a hundred
denarii; and seizing him by the throat, he said, 'Pay what you
owe.' Then his fellow slave fell down and pleaded with him,
'Have pity with me and I will pay you. But he refused; then
he went and threw him into prison until he would pay the
debt. When his fellow slaves saw what had happened, they
were greatly distressed, and they went and reported to their
Lord all that had taken place. Then his Lord summoned him
and said to him, 'You wicked slave! I forgave you all that
debt because you pleaded with me! Should you not have
mercy on your fellow slave, as I had mercy on you? And
in anger his Lord handed him over to be tortured until he
would pay his entire debt. So my heavenly Father will also
do to every one of you, if you do not forgive your brother or
sister from your heart."
Mathew 18:23-35