Skip to content

Commit 8c89dc9

Browse files
committed
docs(notes): add Spring web app setup guide
1 parent 0375849 commit 8c89dc9

File tree

3 files changed

+129
-2
lines changed

3 files changed

+129
-2
lines changed

_posts/en/2025-01-11-notes-en.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ generated: false
77
translated: false
88
---
99

10-
These 2132 notes are primarily generated by AI chatbots. I used them to summarize key points and will walk through them to enhance my understanding.
10+
These 2133 notes are primarily generated by AI chatbots. I used them to summarize key points and will walk through them to enhance my understanding.
1111

1212
* [Core Essentials of LLM Applications](/notes/2025-09-05-core-llm-essentials-en)
13+
* [Spring Web Application Setup Without Boot](/notes/2025-09-05-spring-webapp-setup-en)
1314
* [AI Model Context Window Capacities](/notes/2025-09-03-ai-model-context-window-en)
1415
* [Alphabet Hits $186.66B in H1 2025](/notes/2025-09-03-alphabet-h1-2025-revenue-en)
1516
* [Building Trust Takes Time and Consistency](/notes/2025-09-03-building-trust-consistency-en)
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
---
2+
title: Spring Web Application Setup Without Boot
3+
lang: en
4+
layout: post
5+
audio: false
6+
translated: false
7+
generated: true
8+
image: false
9+
---
10+
11+
Got it. Since you’re using **Java 8** with **Spring 5.2.2** (no Spring Boot here, just core Spring + web), you’ll need to set up a minimal application manually. Below is a simple example showing how to build a web app with one controller.
12+
13+
---
14+
15+
### 1. Add Required Dependencies
16+
17+
You already have `spring-context`, `spring-web`, and `spring-core`. For serving requests, you also need `spring-webmvc`:
18+
19+
```xml
20+
<dependency>
21+
<groupId>org.springframework</groupId>
22+
<artifactId>spring-webmvc</artifactId>
23+
<version>5.2.2.RELEASE</version>
24+
</dependency>
25+
```
26+
27+
---
28+
29+
### 2. Create a Controller
30+
31+
```java
32+
package com.example.demo;
33+
34+
import org.springframework.stereotype.Controller;
35+
import org.springframework.web.bind.annotation.*;
36+
37+
@Controller
38+
public class HelloController {
39+
40+
@ResponseBody
41+
@RequestMapping("/hello")
42+
public String hello() {
43+
return "Hello, Spring Web!";
44+
}
45+
}
46+
```
47+
48+
* `@Controller` tells Spring this is a web controller.
49+
* `@RequestMapping("/hello")` maps to `http://localhost:8080/hello`.
50+
* `@ResponseBody` makes it return plain text (not a JSP).
51+
52+
---
53+
54+
### 3. Define Spring Configuration
55+
56+
Since we’re not using Spring Boot, we must wire things manually.
57+
58+
```java
59+
package com.example.demo;
60+
61+
import org.springframework.context.annotation.*;
62+
import org.springframework.web.servlet.config.annotation.*;
63+
64+
@Configuration
65+
@EnableWebMvc
66+
@ComponentScan(basePackages = "com.example.demo")
67+
public class AppConfig implements WebMvcConfigurer {
68+
}
69+
```
70+
71+
This enables Spring MVC and scans your package for controllers.
72+
73+
---
74+
75+
### 4. Set Up `web.xml` (for Tomcat/Servlet container)
76+
77+
If you’re packaging as a WAR:
78+
79+
```xml
80+
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
81+
version="3.1">
82+
83+
<servlet>
84+
<servlet-name>dispatcher</servlet-name>
85+
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
86+
<init-param>
87+
<param-name>contextClass</param-name>
88+
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
89+
</init-param>
90+
<init-param>
91+
<param-name>contextConfigLocation</param-name>
92+
<param-value>com.example.demo.AppConfig</param-value>
93+
</init-param>
94+
<load-on-startup>1</load-on-startup>
95+
</servlet>
96+
97+
<servlet-mapping>
98+
<servlet-name>dispatcher</servlet-name>
99+
<url-pattern>/</url-pattern>
100+
</servlet-mapping>
101+
102+
</web-app>
103+
```
104+
105+
This sets up the `DispatcherServlet` and loads your `AppConfig`.
106+
107+
---
108+
109+
### 5. Run the App
110+
111+
* Package as a WAR and deploy to Tomcat (or Jetty).
112+
* Start Tomcat and visit:
113+
114+
```
115+
http://localhost:8080/your-app/hello
116+
```
117+
* You should see:
118+
119+
```
120+
Hello, Spring Web!
121+
```
122+
123+
---
124+
125+
👉 Question for you: do you want this app to run inside **Tomcat (WAR deployment)**, or would you prefer a **standalone `main()` launcher** (embedded server, like Spring Boot but minimal)? I can show both ways depending on your setup.

original/2025-01-11-notes-en.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ generated: false
77
translated: false
88
---
99

10-
These 2132 notes are primarily generated by AI chatbots. I used them to summarize key points and will walk through them to enhance my understanding.
10+
These 2133 notes are primarily generated by AI chatbots. I used them to summarize key points and will walk through them to enhance my understanding.
1111

1212
* [Core Essentials of LLM Applications](/notes/2025-09-05-core-llm-essentials-en)
13+
* [Spring Web Application Setup Without Boot](/notes/2025-09-05-spring-webapp-setup-en)
1314
* [AI Model Context Window Capacities](/notes/2025-09-03-ai-model-context-window-en)
1415
* [Alphabet Hits $186.66B in H1 2025](/notes/2025-09-03-alphabet-h1-2025-revenue-en)
1516
* [Building Trust Takes Time and Consistency](/notes/2025-09-03-building-trust-consistency-en)

0 commit comments

Comments
 (0)