or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

tessl/maven-org-springframework-boot--spring-boot-starter-web

Starter for building web, including RESTful, applications using Spring MVC with embedded Tomcat server.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.springframework.boot/spring-boot-starter-web@3.5.x

To install, run

npx @tessl/cli install tessl/maven-org-springframework-boot--spring-boot-starter-web@3.5.0

0

# Spring Boot Starter Web

1

2

Spring Boot Starter Web is a comprehensive dependency starter that provides all necessary components for building web applications using Spring MVC framework. It includes embedded Tomcat server, JSON processing capabilities, and auto-configuration for RESTful services and traditional web applications.

3

4

## Package Information

5

6

- **Package Name**: spring-boot-starter-web

7

- **Package Type**: maven

8

- **Language**: Java

9

- **Group ID**: org.springframework.boot

10

- **Artifact ID**: spring-boot-starter-web

11

- **Installation**: Add dependency to Maven/Gradle build file

12

13

### Maven

14

```xml

15

<dependency>

16

<groupId>org.springframework.boot</groupId>

17

<artifactId>spring-boot-starter-web</artifactId>

18

<version>3.5.3</version>

19

</dependency>

20

```

21

22

### Gradle

23

```gradle

24

implementation 'org.springframework.boot:spring-boot-starter-web:3.5.3'

25

```

26

27

## Core Imports

28

29

```java

30

import org.springframework.boot.SpringApplication;

31

import org.springframework.boot.autoconfigure.SpringBootApplication;

32

import org.springframework.web.bind.annotation.*;

33

import org.springframework.http.ResponseEntity;

34

```

35

36

## Basic Usage

37

38

```java

39

@SpringBootApplication

40

public class WebApplication {

41

public static void main(String[] args) {

42

SpringApplication.run(WebApplication.class, args);

43

}

44

}

45

46

@RestController

47

@RequestMapping("/api")

48

public class UserController {

49

50

@GetMapping("/users/{id}")

51

public ResponseEntity<User> getUser(@PathVariable Long id) {

52

User user = userService.findById(id);

53

return ResponseEntity.ok(user);

54

}

55

56

@PostMapping("/users")

57

public ResponseEntity<User> createUser(@RequestBody User user) {

58

User created = userService.save(user);

59

return ResponseEntity.status(201).body(created);

60

}

61

}

62

```

63

64

## Architecture

65

66

Spring Boot Starter Web is built around several key components:

67

68

- **Auto-Configuration**: Automatically configures Spring MVC, embedded server, and related components

69

- **Embedded Server**: Tomcat server by default (Jetty/Undertow alternatives available)

70

- **Spring MVC Framework**: Full MVC capabilities with annotation-driven development

71

- **Content Negotiation**: Automatic JSON/XML serialization based on request headers

72

- **Error Handling**: Built-in error pages and API error responses

73

- **Static Resource Handling**: Serves static content with caching and versioning support

74

75

## Capabilities

76

77

### Controller Development

78

79

Create RESTful web services and traditional MVC controllers using annotations.

80

81

```java { .api }

82

@RestController

83

@RequestMapping("/api")

84

public class ApiController {

85

@GetMapping("/resource/{id}")

86

public ResponseEntity<Resource> getResource(@PathVariable Long id);

87

88

@PostMapping("/resource")

89

public ResponseEntity<Resource> createResource(@RequestBody Resource resource);

90

}

91

```

92

93

[Controller Development](./controllers.md)

94

95

### Configuration Properties

96

97

Configure web application behavior through application properties.

98

99

```java { .api }

100

// Core server configuration

101

server.port=8080

102

server.servlet.context-path=/myapp

103

104

// MVC configuration

105

spring.mvc.static-path-pattern=/**

106

spring.mvc.async.request-timeout=30s

107

108

// Multipart file uploads

109

spring.servlet.multipart.max-file-size=10MB

110

spring.servlet.multipart.max-request-size=50MB

111

```

112

113

[Configuration Properties](./configuration.md)

114

115

### Error Handling

116

117

Built-in error handling with customizable error pages and API responses.

118

119

```java { .api }

120

@ControllerAdvice

121

public class GlobalExceptionHandler {

122

@ExceptionHandler(ResourceNotFoundException.class)

123

public ResponseEntity<ErrorResponse> handleNotFound(ResourceNotFoundException ex);

124

125

@ExceptionHandler(ValidationException.class)

126

public ResponseEntity<ErrorResponse> handleValidation(ValidationException ex);

127

}

128

```

129

130

[Error Handling](./error-handling.md)

131

132

### Static Resources

133

134

Serve static content like CSS, JavaScript, and images with built-in caching.

135

136

```java { .api }

137

// Default static resource locations

138

// classpath:/META-INF/resources/

139

// classpath:/resources/

140

// classpath:/static/

141

// classpath:/public/

142

143

// Configuration

144

spring.web.resources.static-locations=classpath:/custom-static/

145

spring.web.resources.cache.period=3600

146

```

147

148

[Static Resources](./static-resources.md)

149

150

### JSON Processing

151

152

Automatic JSON serialization and deserialization using Jackson library.

153

154

```java { .api }

155

@Autowired

156

private ObjectMapper objectMapper;

157

158

// Automatic JSON conversion for request/response bodies

159

@PostMapping("/users")

160

public ResponseEntity<User> createUser(@RequestBody User user) {

161

return ResponseEntity.ok(user);

162

}

163

```

164

165

[JSON Processing](./json-processing.md)

166

167

### Bean Validation

168

169

Built-in support for JSR-303/349/380 Bean Validation with automatic validation of request bodies.

170

171

```java { .api }

172

// Automatic validation with @Valid annotation

173

@PostMapping("/users")

174

public ResponseEntity<User> createUser(@Valid @RequestBody User user, BindingResult result) {

175

if (result.hasErrors()) {

176

return ResponseEntity.badRequest().body("Validation failed");

177

}

178

return ResponseEntity.ok(user);

179

}

180

181

// Validation annotations on model classes

182

public class User {

183

@NotBlank(message = "Name is required")

184

@Size(min = 2, max = 50)

185

private String name;

186

187

@Email(message = "Invalid email format")

188

private String email;

189

}

190

```

191

192

### Web Testing

193

194

Comprehensive testing support for web controllers and integration testing.

195

196

```java { .api }

197

@WebMvcTest(UserController.class)

198

class UserControllerTest {

199

@Autowired

200

private MockMvc mockMvc;

201

202

@MockBean

203

private UserService userService;

204

205

@Test

206

void shouldGetUser() throws Exception {

207

mockMvc.perform(get("/users/1"))

208

.andExpect(status().isOk());

209

}

210

}

211

```

212

213

[Web Testing](./testing.md)

214

215

### HTTP Clients

216

217

Auto-configured RestTemplate and RestClient for making HTTP requests to external services.

218

219

```java { .api }

220

@Autowired

221

private RestTemplateBuilder restTemplateBuilder;

222

223

// Create configured RestTemplate

224

RestTemplate restTemplate = restTemplateBuilder

225

.rootUri("https://api.example.com")

226

.setConnectTimeout(Duration.ofSeconds(5))

227

.build();

228

229

// Make HTTP requests

230

User user = restTemplate.getForObject("/users/{id}", User.class, 1L);

231

```

232

233

[HTTP Clients](./http-clients.md)

234

235

### Embedded Server

236

237

Configure and customize the embedded Tomcat server.

238

239

```java { .api }

240

@Bean

241

public WebServerFactoryCustomizer<TomcatServletWebServerFactory> tomcatCustomizer() {

242

return factory -> {

243

factory.setPort(9090);

244

factory.setContextPath("/app");

245

};

246

}

247

```

248

249

[Embedded Server](./embedded-server.md)

250

251

## Core Types

252

253

```java { .api }

254

// HTTP response wrapper

255

public class ResponseEntity<T> {

256

public static <T> ResponseEntity<T> ok(T body);

257

public static <T> ResponseEntity<T> status(HttpStatus status);

258

public static ResponseEntity<?> noContent();

259

}

260

261

// HTTP status codes

262

public enum HttpStatus {

263

OK(200), CREATED(201), NO_CONTENT(204),

264

BAD_REQUEST(400), NOT_FOUND(404), INTERNAL_SERVER_ERROR(500);

265

}

266

267

// Request/Response body binding

268

public interface HttpMessageConverter<T> {

269

boolean canRead(Class<?> clazz, MediaType mediaType);

270

boolean canWrite(Class<?> clazz, MediaType mediaType);

271

T read(Class<? extends T> clazz, HttpInputMessage inputMessage);

272

void write(T t, MediaType contentType, HttpOutputMessage outputMessage);

273

}

274

```