Modernize project foundation and configuration

This commit is contained in:
hoelee committed 2026-08-19 21:17:18 +08:00
1 parent 1c12977744
commit 053afab44d
8 files changed
+164 -71

No files matched your search

@@ -0,0 +1,23 @@
package com.hoelee.jsonplaceholder;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
/**
* @version v1, 2024-10-21 08:05:00PM
* @author hoelee
* Learning note: configuration scanning and JPA auditing keep cross-cutting setup explicit and compact.
*/
@SpringBootApplication
@ConfigurationPropertiesScan
@EnableJpaAuditing
public class ShowcaseApplication {
public static void main(String[] args) {
SpringApplication.run(ShowcaseApplication.class, args);
}
}
//~ v1, 2024-10-21 08:05:00PM - Last edited by hoelee
@@ -0,0 +1,23 @@
package com.hoelee.jsonplaceholder.config;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import java.time.Duration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;
/**
* @version v1, 2024-10-21 09:05:00PM
* @author hoelee
* Learning note: typed, validated properties make operational settings discoverable and fail fast.
*/
@Validated
@ConfigurationProperties(prefix = "app.api")
public record ApiProperties(
@NotBlank String jsonPlaceholderBaseUrl,
Duration requestTimeout,
@Min(1) @Max(100) int importLimit) {
}
//~ v1, 2024-10-21 09:05:00PM - Last edited by hoelee
@@ -0,0 +1,19 @@
package com.hoelee.jsonplaceholder.config;
import jakarta.validation.constraints.NotBlank;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;
/**
* @version v1, 2024-10-21 10:05:00PM
* @author hoelee
* Learning note: credentials are externalized so a repository never needs a real environment secret.
*/
@Validated
@ConfigurationProperties(prefix = "app.security")
public record SecurityProperties(
@NotBlank String editorUsername,
@NotBlank String editorPassword) {
}
//~ v1, 2024-10-21 10:05:00PM - Last edited by hoelee
+35
View File
@@ -0,0 +1,35 @@
spring:
application:
name: jsonplaceholder-showcase
datasource:
url: jdbc:h2:mem:postshowcase;MODE=PostgreSQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
username: sa
password:
jpa:
open-in-view: false
hibernate:
ddl-auto: update
cache:
caffeine:
spec: maximumSize=500,expireAfterWrite=10m
mvc:
problemdetails:
enabled: true
management:
endpoints:
web:
exposure:
include: health,info
endpoint:
health:
show-details: never
app:
api:
json-placeholder-base-url: https://jsonplaceholder.typicode.com
request-timeout: 2s
import-limit: 20
security:
editor-username: ${APP_EDITOR_USERNAME:demo-editor}
editor-password: ${APP_EDITOR_PASSWORD:changeit}