Java Spring Get
-
@GetMappingis a shortcut for@RequestMapping(method = GET, path = …)
@GetMapping({"/health", "/.well-known/health"})
public Map<String, String> health() {
return Map.of("status","ok","env","dev");
}
- The array means map both routes to this one handler
Build Properties
- Values like groupId, artifactId, version are stored in
META-INF/build-info.properties -
META-INF/build-info.propertiesis generated at build time by the Spring Boot Maven plugin’s build-info goal - To ensure it’s always there, configure the plugin to run the goal during
process-resourcesinpom.xml pluginManagementonly declares defaults; it does not execute plugins
Dependency Injection
Without
// Concrete types hard-coded inside Car
class PetrolEngine { void start() { System.out.println("vroom"); } }
class AlloyWheel {}
class LeadAcidBattery {}
class Car {
private final PetrolEngine engine = new PetrolEngine();
private final AlloyWheel wheel = new AlloyWheel();
private final LeadAcidBattery battery = new LeadAcidBattery();
void start() { engine.start(); }
}
With
class Car {
private final Engine engine;
private final Wheel wheel;
private final Battery battery;
Car(Engine engine, Wheel wheel, Battery battery) {
this.engine = engine;
this.wheel = wheel;
this.battery = battery;
}
void start() { engine.start(); }
}
Store environment values (env, port, dry_run, timezone) in .properties file
about pluginManagement
<build>
<pluginManagement>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>build-info</id>
<phase>process-resources</phase>
<goals><goal>build-info</goal></goals>
</execution>
</executions>
</plugin>
</pluginManagement>
</build>
has to be
<build>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>build-info</id>
<phase>process-resources</phase>
<goals><goal>build-info</goal></goals>
</execution>
</executions>
</plugin>
</build>