Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
••••••••••••••••••••
Intelligence View
⚡ tsecurity.de Intelligence

PART 7 :CONTROLLER ALL CONCEPT IN SPRINGBOOT PROJECT

🚀 Controller Return Types - COMPLETE DEEP DIVE 📊 ALL POSSIBLE RETURN TYPES IN SPRING BOOT CONTROLLER ┌─────────────────────────────────────────────────────┐ │ Spring Boot Controller - Return Type Options │ ├───────…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!




🚀 Controller Return Types - COMPLETE DEEP DIVE









📊 ALL POSSIBLE RETURN TYPES IN SPRING BOOT CONTROLLER






┌─────────────────────────────────────────────────────┐
│ Spring Boot Controller - Return Type Options │
├─────────────────────────────────────────────────────┤
│ │
│ 1️⃣ Direct Object/Primitive │
│ 2️⃣ ResponseEntity<T> │
│ 3️⃣ HttpEntity<T> │
│ 4️⃣ String (View Name) │
│ 5️⃣ void │
│ 6️⃣ ModelAndView │
│ 7️⃣ @ResponseBody with Object │
│ 8️⃣ DeferredResult<T> (Async) │
│ 9️⃣ Callable<T> (Async) │
│ 🔟 CompletableFuture<T> (Async) │
│ 1️⃣1️⃣ Flux<T> / Mono<T> (Reactive) │
│ 1️⃣2️⃣ StreamingResponseBody │
│ 1️⃣3️⃣ ResponseBodyEmitter │
│ 1️⃣4️⃣ SseEmitter (Server-Sent Events) │
│ 1️⃣5️⃣ Resource (File Download) │
│ 1️⃣6️⃣ byte[] / ByteArrayResource │
│ 1️⃣7️⃣ HttpHeaders │
│ 1️⃣8️⃣ Map<String, Object> │
│ │
└─────────────────────────────────────────────────────┘












1️⃣ DIRECT OBJECT RETURN - Simplest






How it Works:






@RestController
@RequestMapping("/api/users")
public class UserController {

// Direct object return
@GetMapping("/{id}")
public User getUser(@PathVariable Long id) {
return userService.findById(id);
}

// List return
@GetMapping
public List<User> getAllUsers() {
return userService.findAll();
}

// Primitive return
@GetMapping("/count")
public long getUserCount() {
return userService.count();
}

// String return
@GetMapping("/message")
public String getMessage() {
return "Hello World";
}
}









What Happens Behind the Scenes:






1. Spring Framework receives your object
↓
2. HttpMessageConverter kicks in
↓
3. Jackson (default JSON converter) converts object to JSON
↓
4. Sets Content-Type: application/json automatically
↓
5. Sets Status Code: 200 OK automatically
↓
6. Returns response to client









Response:






// User object automatically converted to JSON
{
"id": 123,
"name": "Raj",
"email": "[email protected]"
}









Limitations:






❌ Cannot control status code (always 200)
❌ Cannot add custom headers
❌ Cannot handle errors properly
❌ No control over response format












2️⃣ ResponseEntity - MOST CONTROL






How it Works:






@RestController
@RequestMapping("/api/users")
public class UserController {

// Full control over response
@GetMapping("/{id}")
public ResponseEntity<User> getUser(@PathVariable Long id) {
User user = userService.findById(id);

if (user != null) {
return ResponseEntity
.ok() // 200 OK
.header("X-Custom-Header", "value")
.body(user);
} else {
return ResponseEntity
.notFound() // 404 Not Found
.build();
}
}

// Create with 201 status
@PostMapping
public ResponseEntity<User> createUser(@RequestBody User user) {
User created = userService.save(user);

URI location = ServletUriComponentsBuilder
.fromCurrentRequest()
.path("/{id}")
.buildAndExpand(created.getId())
.toUri();

return ResponseEntity
.created(location) // 201 Created
.body(created);
}

// Delete with 204 status
@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteUser(@PathVariable Long id) {
userService.delete(id);
return ResponseEntity.noContent().build(); // 204 No Content
}
}









Behind the Scenes:






1. You create ResponseEntity object
↓
2. Set status code explicitly (200, 201, 404, etc)
↓
3. Set headers if needed
↓
4. Set body (optional)
↓
5. Spring Framework takes ResponseEntity
↓
6. Extracts status, headers, body
↓
7. Builds HTTP response
↓
8. Returns to client









Class Hierarchy:






// ResponseEntity source code (simplified)
package org.springframework.http;

public class ResponseEntity<T> extends HttpEntity<T> {

private final HttpStatusCode status;

// Constructor
public ResponseEntity(T body, HttpHeaders headers, HttpStatusCode status) {
super(body, headers);
this.status = status;
}

// Static factory methods
public static BodyBuilder ok() {
return status(HttpStatus.OK);
}

public static <T> ResponseEntity<T> ok(T body) {
return ok().body(body);
}

public static BodyBuilder created(URI location) {
return status(HttpStatus.CREATED).location(location);
}

// ... more methods
}









Advantages:






✅ Full control over status code
✅ Can add custom headers
✅ Can handle different scenarios (success/error)
✅ Type-safe with generics
✅ Industry standard












3️⃣ HttpEntity - ResponseEntity ka Parent






How it Works:






@RestController
public class UserController {

// HttpEntity - no status code control
@GetMapping("/users/{id}")
public HttpEntity<User> getUser(@PathVariable Long id) {
User user = userService.findById(id);

HttpHeaders headers = new HttpHeaders();
headers.add("X-Custom-Header", "value");

return new HttpEntity<>(user, headers);
// Always returns 200 OK (no status control)
}
}









Behind the Scenes:






// HttpEntity source code (simplified)
package org.springframework.http;

public class HttpEntity<T> {

private final HttpHeaders headers;
private final T body;

public HttpEntity(T body) {
this(body, null);
}

public HttpEntity(T body, HttpHeaders headers) {
this.body = body;
this.headers = headers != null ? headers : new HttpHeaders();
}

public T getBody() {
return this.body;
}

public HttpHeaders getHeaders() {
return this.headers;
}
}









Use Case:






✅ When you need headers but don't care about status
❌ Rarely used (ResponseEntity is better)












4️⃣ String Return - View Name (Thymeleaf/JSP)






How it Works:






@Controller  // NOT @RestController
@RequestMapping("/web")
public class WebController {

// Returns view name (not JSON)
@GetMapping("/home")
public String home(Model model) {
model.addAttribute("message", "Welcome");
return "home"; // Looks for home.html in templates/
}

// Redirect
@GetMapping("/redirect")
public String redirect() {
return "redirect:/web/home";
}

// Forward
@GetMapping("/forward")
public String forward() {
return "forward:/web/home";
}
}









Behind the Scenes:






1. Spring MVC receives String return
↓
2. ViewResolver kicks in
↓
3. Looks for template: templates/home.html
↓
4. Thymeleaf/JSP processes template
↓
5. Returns rendered HTML
↓
6. Client receives HTML page









Use Case:






✅ Traditional web applications (HTML pages)
✅ Server-side rendering
❌ NOT for REST APIs












5️⃣ void Return - No Response Body






How it Works:






@RestController
public class LogController {

// void - no response body
@PostMapping("/log")
public void logEvent(@RequestBody LogRequest request) {
logService.log(request);
// Returns 200 OK with empty body
}

// void with @ResponseStatus
@PostMapping("/event")
@ResponseStatus(HttpStatus.ACCEPTED) // 202 Accepted
public void createEvent(@RequestBody Event event) {
eventService.create(event);
}
}









Behind the Scenes:






1. Method executes
↓
2. No return value
↓
3. Spring sets status 200 OK by default
↓
4. Response body is empty
↓
5. Client receives empty response









Use Case:






✅ Fire-and-forget operations
✅ Logging, auditing
❌ Client doesn't know if operation succeeded
❌ Cannot return data












6️⃣ ModelAndView - MVC Pattern






How it Works:






@Controller
public class ProductController {

@GetMapping("/products")
public ModelAndView getProducts() {
ModelAndView mav = new ModelAndView();
mav.setViewName("products"); // View name
mav.addObject("products", productService.findAll()); // Data
return mav;
}

// Alternative
@GetMapping("/product/{id}")
public ModelAndView getProduct(@PathVariable Long id) {
Product product = productService.findById(id);
return new ModelAndView("product-detail", "product", product);
}
}









Behind the Scenes:






// ModelAndView source code (simplified)
package org.springframework.web.servlet;

public class ModelAndView {

private Object view; // View name or View object
private ModelMap model; // Data for view
private HttpStatus status;

public void setViewName(String viewName) {
this.view = viewName;
}

public void addObject(String name, Object value) {
getModelMap().addAttribute(name, value);
}
}









Use Case:






✅ Traditional Spring MVC
✅ Server-side rendering
❌ NOT for REST APIs












7️⃣ @ResponseBody with Object - Auto JSON






How it Works:






@Controller  // Regular Controller
@RequestMapping("/api")
public class ApiController {

@GetMapping("/users")
@ResponseBody // Converts to JSON
public List<User> getUsers() {
return userService.findAll();
}

// @RestController = @Controller + @ResponseBody on all methods
}









Behind the Scenes:






@ResponseBody annotation tells Spring:
↓
"Don't look for a view, serialize this object to JSON"
↓
HttpMessageConverter converts object to JSON
↓
Returns JSON response









Note:






@RestController = @Controller + @ResponseBody (on every method)

So these are same:
1. @RestController with no @ResponseBody
2. @Controller with @ResponseBody on each method












8️⃣ DeferredResult - ASYNC Processing






How it Works:






@RestController
public class AsyncController {

@GetMapping("/async-data")
public DeferredResult<String> getAsyncData() {
DeferredResult<String> result = new DeferredResult<>(5000L); // 5 sec timeout

// Process in background thread
CompletableFuture.runAsync(() -> {
try {
Thread.sleep(2000); // Simulate long operation
result.setResult("Async data ready!");
} catch (Exception e) {
result.setErrorResult("Failed!");
}
});

// Return immediately (non-blocking)
return result;
}
}









Behind the Scenes:






1. Request comes in
↓
2. DeferredResult created and returned immediately
↓
3. Request thread is FREE (can handle other requests)
↓
4. Background thread processes
↓
5. setResult() called when ready
↓
6. Spring sends response to client
↓
7. Client gets response after 2 seconds









Use Case:






✅ Long-running operations
✅ External API calls
✅ Database queries
✅ High concurrency needed












9️⃣ Callable - ASYNC Simple






How it Works:






@RestController
public class AsyncController {

@GetMapping("/callable-data")
public Callable<String> getCallableData() {
return () -> {
Thread.sleep(2000); // Long operation
return "Data ready!";
};
}

@GetMapping("/users/async")
public Callable<List<User>> getUsersAsync() {
return () -> {
// Long database query
return userService.findAll();
};
}
}









Behind the Scenes:






1. Request comes in
↓
2. Spring puts Callable in TaskExecutor queue
↓
3. Request thread is FREE
↓
4. Background thread executes Callable
↓
5. Result returned when ready
↓
6. Client gets response









Difference: Callable vs DeferredResult:






Callable:
- Spring manages threading automatically
- Simpler code
- Less control

DeferredResult:
- You manage threading
- More control
- Can integrate with external systems












🔟 CompletableFuture - Modern ASYNC






How it Works:






@RestController
public class AsyncController {

@Autowired
private AsyncService asyncService;

@GetMapping("/future-data")
public CompletableFuture<ResponseEntity<String>> getFutureData() {
return asyncService.processAsync()
.thenApply(result -> ResponseEntity.ok(result))
.exceptionally(ex -> ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body("Error: " + ex.getMessage())
);
}

@GetMapping("/users/future")
public CompletableFuture<List<User>> getUsersFuture() {
return CompletableFuture.supplyAsync(() -> {
return userService.findAll();
});
}
}









Behind the Scenes:






// AsyncService
@Service
public class AsyncService {

@Async
public CompletableFuture<String> processAsync() {
return CompletableFuture.supplyAsync(() -> {
// Long operation
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return "Processed!";
});
}
}









Use Case:






✅ Modern async programming
✅ Complex async workflows
✅ Chaining multiple async operations
✅ Better error handling












1️⃣1️⃣ Flux / Mono - REACTIVE (WebFlux)






How it Works:






@RestController
public class ReactiveController {

// Mono - Single value (like Optional)
@GetMapping("/user/{id}")
public Mono<User> getUser(@PathVariable Long id) {
return userReactiveRepository.findById(id);
}

// Flux - Stream of values
@GetMapping(value = "/users/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<User> streamUsers() {
return userReactiveRepository.findAll()
.delayElements(Duration.ofSeconds(1)); // Emit 1 user per second
}

// Flux to List
@GetMapping("/users")
public Flux<User> getAllUsers() {
return userReactiveRepository.findAll();
}
}









Behind the Scenes:






Traditional (Blocking):
Request → Wait → Database → Wait → Response
(Thread blocked entire time)

Reactive (Non-blocking):
Request → Register callback → Thread FREE
Database ready → Callback fired → Response
(Thread only used when needed)









Dependency:






<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>









Use Case:






✅ High-throughput applications
✅ Streaming data
✅ Real-time updates
✅ Backpressure handling
❌ Complex learning curve












1️⃣2️⃣ StreamingResponseBody - Large File Streaming






How it Works:






@RestController
public class FileController {

@GetMapping("/download/large-file")
public ResponseEntity<StreamingResponseBody> downloadLargeFile() {

StreamingResponseBody stream = outputStream -> {
// Read file in chunks and write to output
try (InputStream inputStream = new FileInputStream("large-file.zip")) {
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
}
};

return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=large-file.zip")
.body(stream);
}
}









Behind the Scenes:






1. Client requests file
↓
2. StreamingResponseBody returned immediately
↓
3. File streamed in chunks (not loaded in memory)
↓
4. Client receives data as it's streamed
↓
5. No OutOfMemory errors for large files









Use Case:






✅ Large file downloads (GB files)
✅ Video streaming
✅ Database export
✅ Report generation












1️⃣3️⃣ ResponseBodyEmitter - Stream Multiple Objects






How it Works:






@RestController
public class StreamController {

@GetMapping("/stream/data")
public ResponseBodyEmitter streamData() {
ResponseBodyEmitter emitter = new ResponseBodyEmitter();

// Send data asynchronously
CompletableFuture.runAsync(() -> {
try {
for (int i = 0; i < 10; i++) {
emitter.send("Data " + i, MediaType.TEXT_PLAIN);
Thread.sleep(1000); // 1 second delay
}
emitter.complete();
} catch (Exception e) {
emitter.completeWithError(e);
}
});

return emitter;
}

@GetMapping("/stream/users")
public ResponseBodyEmitter streamUsers() {
ResponseBodyEmitter emitter = new ResponseBodyEmitter();

CompletableFuture.runAsync(() -> {
try {
List<User> users = userService.findAll();
for (User user : users) {
emitter.send(user); // Send one by one
Thread.sleep(500);
}
emitter.complete();
} catch (Exception e) {
emitter.completeWithError(e);
}
});

return emitter;
}
}









Behind the Scenes:






1. ResponseBodyEmitter returned immediately
↓
2. Connection kept open
↓
3. Data sent progressively via send()
↓
4. Client receives data as it arrives
↓
5. complete() closes connection









Use Case:






✅ Progress updates
✅ Live data feeds
✅ Batch processing updates












1️⃣4️⃣ SseEmitter - Server-Sent Events






How it Works:






@RestController
public class NotificationController {

private final List<SseEmitter> emitters = new CopyOnWriteArrayList<>();

// Client subscribes to notifications
@GetMapping("/notifications/subscribe")
public SseEmitter subscribe() {
SseEmitter emitter = new SseEmitter(Long.MAX_VALUE);

emitters.add(emitter);

emitter.onCompletion(() -> emitters.remove(emitter));
emitter.onTimeout(() -> emitters.remove(emitter));

return emitter;
}

// Send notification to all subscribers
@PostMapping("/notifications/send")
public void sendNotification(@RequestBody String message) {
List<SseEmitter> deadEmitters = new ArrayList<>();

emitters.forEach(emitter -> {
try {
emitter.send(SseEmitter.event()
.name("notification")
.data(message));
} catch (Exception e) {
deadEmitters.add(emitter);
}
});

emitters.removeAll(deadEmitters);
}
}









Behind the Scenes:






1. Client subscribes (GET /notifications/subscribe)
↓
2. SseEmitter created and returned
↓
3. Connection stays open
↓
4. Server sends events via send()
↓
5. Client receives real-time updates
↓
6. No polling needed









Client Side (JavaScript):






const eventSource = new EventSource('/notifications/subscribe');

eventSource.addEventListener('notification', (event) => {
console.log('Received:', event.data);
});









Use Case:






✅ Real-time notifications
✅ Live sports scores
✅ Stock price updates
✅ Chat applications
✅ Activity feeds












1️⃣5️⃣ Resource - File Download






How it Works:






@RestController
public class FileDownloadController {

@GetMapping("/download/file")
public ResponseEntity<Resource> downloadFile() {
File file = new File("report.pdf");
Resource resource = new FileSystemResource(file);

return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_PDF)
.header(HttpHeaders.CONTENT_DISPOSITION,
"attachment; filename=\"" + file.getName() + "\"")
.body(resource);
}

@GetMapping("/download/classpath")
public ResponseEntity<Resource> downloadClasspathFile() {
Resource resource = new ClassPathResource("static/template.xlsx");

return ResponseEntity.ok()
.contentType(MediaType.parseMediaType(
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
))
.header(HttpHeaders.CONTENT_DISPOSITION,
"attachment; filename=\"template.xlsx\"")
.body(resource);
}
}









Resource Types:






// FileSystemResource - file from file system
Resource resource = new FileSystemResource("/path/to/file.pdf");

// ClassPathResource - file from classpath (src/main/resources)
Resource resource = new ClassPathResource("static/file.pdf");

// UrlResource - file from URL
Resource resource = new UrlResource("http://example.com/file.pdf");

// ByteArrayResource - from byte array
Resource resource = new ByteArrayResource(fileBytes);

// InputStreamResource - from InputStream
Resource resource = new InputStreamResource(inputStream);









Use Case:






✅ File downloads
✅ Report generation
✅ Template downloads
✅ Export functionality












1️⃣6️⃣ byte[] - Binary Data






How it Works:






@RestController
public class ImageController {

@GetMapping("/image/{id}")
public ResponseEntity<byte[]> getImage(@PathVariable Long id) {
byte[] imageBytes = imageService.getImageBytes(id);

return ResponseEntity.ok()
.contentType(MediaType.IMAGE_JPEG)
.body(imageBytes);
}

@GetMapping("/pdf/{id}")
public ResponseEntity<byte[]> getPdf(@PathVariable Long id) {
byte[] pdfBytes = pdfService.generatePdf(id);

return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_PDF)
.header(HttpHeaders.CONTENT_DISPOSITION,
"attachment; filename=\"report.pdf\"")
.body(pdfBytes);
}
}









Behind the Scenes:






1. byte[] returned
↓
2. Spring writes bytes directly to response
↓
3. No conversion needed
↓
4. Client receives binary data









Use Case:






✅ Images
✅ PDFs
✅ Excel files
✅ Any binary data
⚠️ WARNING: Load entire file in memory (use streaming for large files)












1️⃣7️⃣ HttpHeaders - Just Headers






How it Works:






@RestController
public class HeaderController {

@RequestMapping(value = "/options", method = RequestMethod.OPTIONS)
public ResponseEntity<Void> options() {
HttpHeaders headers = new HttpHeaders();
headers.setAllow(Set.of(
HttpMethod.GET,
HttpMethod.POST,
HttpMethod.PUT,
HttpMethod.DELETE,
HttpMethod.OPTIONS
));

return ResponseEntity.ok().headers(headers).build();
}
}









Use Case:






✅ OPTIONS requests
✅ CORS preflight
✅ Header-only responses












1️⃣8️⃣ Map - Dynamic Response






How it Works:






@RestController
public class DynamicController {

@GetMapping("/stats")
public Map<String, Object> getStats() {
Map<String, Object> stats = new HashMap<>();
stats.put("totalUsers", userService.count());
stats.put("activeUsers", userService.countActive());
stats.put("timestamp", System.currentTimeMillis());
return stats;
}

@GetMapping("/data")
public ResponseEntity<Map<String, Object>> getData() {
Map<String, Object> data = new HashMap<>();
data.put("success", true);
data.put("data", userService.findAll());
data.put("count", userService.count());

return ResponseEntity.ok(data);
}
}









Response:






{
"totalUsers": 1000,
"activeUsers": 750,
"timestamp": 1709388000000
}









Use Case:






✅ Quick prototyping
✅ Dynamic fields
❌ Not type-safe
❌ Not recommended for production












📊 COMPARISON TABLE








































































































































Return Type Status Control Headers Control Async Use Case Complexity
Object ❌ ❌ ❌ Simple APIs ⭐
ResponseEntity ✅ ✅ ❌ Most APIs ⭐⭐
HttpEntity ❌ ✅ ❌ Rare ⭐⭐
String ❌ ❌ ❌ MVC Views ⭐
void ⚠️ ❌ ❌ Fire-forget ⭐
ModelAndView ❌ ❌ ❌ MVC ⭐⭐
DeferredResult ✅ ✅ ✅ Async ⭐⭐⭐
Callable ❌ ❌ ✅ Simple Async ⭐⭐
CompletableFuture ✅ ✅ ✅ Modern Async ⭐⭐⭐
Flux/Mono ✅ ✅ ✅ Reactive ⭐⭐⭐⭐
StreamingResponseBody ✅ ✅ ✅ Large files ⭐⭐⭐
ResponseBodyEmitter ✅ ✅ ✅ Streaming ⭐⭐⭐
SseEmitter ✅ ✅ ✅ Real-time ⭐⭐⭐
Resource ✅ ✅ ❌ File download ⭐⭐
byte[] ✅ ✅ ❌ Binary data ⭐⭐








🎯 DECISION TREE - Which to Use?






Need to return data?
├─ Simple JSON response?
│ ├─ Need status/headers control? → ResponseEntity<T>
│ └─ Don't care about status? → Direct Object
│
├─ File download?
│ ├─ Small file? → Resource or byte[]
│ └─ Large file? → StreamingResponseBody
│
├─ Async processing?
│ ├─ Simple async? → Callable<T>
│ ├─ Complex async? → CompletableFuture<T>
│ └─ Full control? → DeferredResult<T>
│
├─ Real-time updates?
│ ├─ Server-sent events? → SseEmitter
│ ├─ Streaming objects? → ResponseBodyEmitter
│ └─ Reactive? → Flux<T> / Mono<T>
│
├─ HTML page?
│ ├─ With data? → ModelAndView
│ └─ Just redirect? → String
│
└─ No response needed?
└─ void with @ResponseStatus












💡 BEST PRACTICES






1. For REST APIs (90% cases):






// ✅ RECOMMENDED
@RestController
public class UserController {

@GetMapping("/users/{id}")
public ResponseEntity<ApiResponse<UserResponse>> getUser(@PathVariable Long id) {
UserResponse user = userService.findById(id);
return ResponseEntity.ok(ApiResponse.success(user));
}
}









2. For Simple Cases:






// ✅ OK for simple endpoints
@RestController
public class HealthController {

@GetMapping("/health")
public String health() {
return "OK";
}
}









3. For File Downloads:






// ✅ RECOMMENDED
@GetMapping("/download")
public ResponseEntity<Resource> download() {
Resource resource = new FileSystemResource(file);
return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_PDF)
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=file.pdf")
.body(resource);
}









4. For Async Operations:






// ✅ RECOMMENDED (Modern)
@GetMapping("/async")
public CompletableFuture<ResponseEntity<Data>> getAsync() {
return service.processAsync()
.thenApply(ResponseEntity::ok)
.exceptionally(ex -> ResponseEntity.status(500).build());
}












🚫 WHAT NOT TO DO






// ❌ DON'T: Mix concerns
@GetMapping("/users")
public Object getUsers() { // Bad: Object type
return userService.findAll();
}

// ❌ DON'T: Return null
@GetMapping("/user")
public User getUser() {
return null; // Bad: NullPointerException
}

// ❌ DON'T: Ignore errors
@GetMapping("/data")
public Data getData() {
return service.getData(); // Bad: What if exception?
}

// ✅ DO: Handle properly
@GetMapping("/data")
public ResponseEntity<Data> getData() {
try {
return ResponseEntity.ok(service.getData());
} catch (Exception e) {
return ResponseEntity.status(500).build();
}
}












📚 SUMMARY - Quick Reference






// 🔥 MOST USED (80% of cases)
ResponseEntity<T> // Full control REST API
Object (User, List<User>) // Simple REST API

// 🎯 SPECIFIC USE CASES
Resource / byte[] // File downloads
CompletableFuture<T> // Async operations
SseEmitter // Real-time updates
StreamingResponseBody // Large file streaming

// 🌐 WEB PAGES (Not REST)
String // View name
ModelAndView // MVC with data

// ⚡ REACTIVE
Flux<T> / Mono<T> // WebFlux reactive

// ❌ RARELY USED
HttpEntity<T> // Use ResponseEntity instead
void // Use ResponseEntity<Void>
Map<String, Object> // Not type-safe






Yeh complete guide hai - save kar lo! Interview aur production code dono mein kaam aayega! 🚀

SOC Incident Playbook: Remote Code Execution (RCE) Defense
Syntax validiert (0 Fehler)
title: Detect Exploitation - PART 7 :CONTROLLER ALL CONCEPT IN SPRINGBOOT PROJECT
id: 4df88e32-6297-4abe-b624-5c3f25afa797
status: experimental
description: Automatisch generierte SIEM-Erkennungsregel basierend auf CTI Intelligence
references:
  - https://tsecurity.de/
author: iShareStuff CTI Automated Detection Engine
date: 2026-09-25
logsource:
  category: network_connection
  product: any
detection:
  selection:
      CommandLine|contains:
        - 'exploit'
  condition: selection
falsepositives:
  - Legitime administrative Zugriffe oder Penetrationstests
level: high
tags:
  - attack.initial_access
Syntax validiert (0 Fehler)
rule CTI_Threat_Indicator {
    meta:
        author = "iShareStuff CTI Automated Detection Engine"
        date = "2026-09-25"
        description = "YARA Signature for "
    strings:
        $str = "PART 7 :CONTROLLER ALL CONCEPT" ascii wide
    condition:
        any of them
}
Syntax validiert (0 Fehler)
index=security sourcetype IN ("cisco:asa", "pan:traffic", "zeek_conn", "suricata", "WinEventLog:Security")
("PART 7 CONTROLLER ALL CONCEPT IN SPRINGB")
| stats count earliest(_time) as first_seen latest(_time) as last_seen by src_ip, dest_ip, dest_host, signature
| eval first_seen=strftime(first_seen, "%Y-%m-%d %H:%M:%S"), last_seen=strftime(last_seen, "%Y-%m-%d %H:%M:%S")
| sort - count
Syntax validiert (0 Fehler)
message: "*PART 7 CONTROLLER ALL CONCEPT IN SPRINGB*"
Syntax validiert (0 Fehler)
CommonSecurityLog
| where Message has "PART 7 CONTROLLER ALL CONCEPT IN SPRINGB"
| summarize EventCount = count(), FirstSeen = min(TimeGenerated), LastSeen = max(TimeGenerated) by SourceIP, DestinationIP, DestinationPort, Activity
| extend DetectionRule = "iShareStuff-CTI-Compiled"
| sort by EventCount desc
🎯
MITRE ATT&CK Matrix Navigator 14 Taktiken
Reconnaissance
-
Resource Development
-
Initial Access
Execution
Persistence
-
Privilege Escalation
Defense Evasion
Credential Access
-
Discovery
-
Lateral Movement
-
Collection
-
Command and Control
Exfiltration
-
Impact
tsecurity.de Cognitive Threat RAG
Fokus-Vektor:

Kognitive Analyse für identifizierte Bedrohung: Erhöhte Bedrohungslage im Bereich PART 7 :CONTROLLER ALL CONCEPT IN SPRING.... Basierend auf 368k Vektor-Korrelationen werden sofortige Isolationsmaßnahmen für betroffene Endpunkte empfohlen.

🛡️ Angriffsfläche & Exposure

Netzwerk/Remote-Zugriff ohne Vorauthentifizierung möglich.

⚡ Empfohlene Sofortmaßnahmen
  • 1. Perimeter-Inspektion: Relevante Portfreigaben und exponierte Endpunkte unverzüglich scannen.
  • 2. Patch-Applikation: Hersteller-Hotfix einspielen oder betroffene Daemons in isolierte DMZ-Segmente überführen.
  • 3. Telemetrie & EDR-Alerts: Prozessaufrufe und Child-Processes auf anomale Shell-Spawns überwachen.
🔗 Semantisch verwandte Zero-Days MariaDB 11.7 VEC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten PART 7 :CONTROLLER ALL CONCEPT IN SPRINGBOOT PROJECT

Thematisch verwandte Begriffe: PART, CONTROLLER, CONCEPT, SPRINGBOOT · 6 Treffer

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-87722 | Uncontrolled Resource Consumption (CWE-400 / CWE-1333) in regex search q…
Advisory →
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel • Rechts: nächster Artikel • unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel TTP ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...
↗ Original-Quelle