0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Sep 5 2025 note

Last updated at Posted at 2025-09-05

Java Spring Get

  • @GetMapping is 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.properties is 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-resources in pom.xml
  • pluginManagement only 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>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?