S SmartDocs
Series: spring boot java 29 lines · Updated 2026-02-03

PublicController.java

spring_boot/code/advanced/src/main/java/com/example/demo/controller/PublicController.java

package com.example.demo.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * Controller for public (unauthenticated) endpoints.
 * <p>
 * These paths are configured as {@code permitAll()} in {@link com.example.demo.config.SecurityConfig},
 * so no HTTP Basic or form login is required. Useful for health checks, status pages, or public info.
 */
@RestController
@RequestMapping("/api/public")
public class PublicController {

    /**
     * GET /api/public/health — simple health check (no auth).
     * Returns a minimal JSON body with status "UP". Can be used by load balancers or monitoring.
     *
     * @return map with key "status" and value "UP"
     */
    @GetMapping("/health")
    public Map<String, String> health() {
        return Map.of("status", "UP");
    }
}

Related articles

spring boot java Updated 2026-02-03

DemoApplication.java

DemoApplication.java — java source code from the spring boot learning materials (spring_boot/code/advanced/src/main/java/com/example/demo/DemoApplication.java).

Read article →
spring boot java Updated 2026-02-03

CustomHealthIndicator.java

CustomHealthIndicator.java — java source code from the spring boot learning materials (spring_boot/code/advanced/src/main/java/com/example/demo/actuator/CustomHealthIndicator.java).

Read article →
spring boot java Updated 2026-02-03

SecurityConfig.java

SecurityConfig.java — java source code from the spring boot learning materials (spring_boot/code/advanced/src/main/java/com/example/demo/config/SecurityConfig.java).

Read article →
spring boot java Updated 2026-02-03

ProductController.java

ProductController.java — java source code from the spring boot learning materials (spring_boot/code/advanced/src/main/java/com/example/demo/controller/ProductController.java).

Read article →
spring boot java Updated 2026-02-03

ProductCreateRequest.java

ProductCreateRequest.java — java source code from the spring boot learning materials (spring_boot/code/advanced/src/main/java/com/example/demo/dto/ProductCreateRequest.java).

Read article →
spring boot java Updated 2026-02-03

ProductUpdateRequest.java

ProductUpdateRequest.java — java source code from the spring boot learning materials (spring_boot/code/advanced/src/main/java/com/example/demo/dto/ProductUpdateRequest.java).

Read article →