SPRING / CATATAN</>↗Spring02 Jul 2026
External configuration means keeping settings such as application names, URLs, ports, feature flags, credentials, or environment-specific values outside your Java code. Spring supports this mainly through: application.properties application.yml environment variables command-line arguments external property files @Value @ConfigurationProperties 1. Using application.properties In a Spring or Spring Boot application, you can place configuration in: src/main/resources/application...
SPRING / CATATAN</>↗Spring02 Jul 2026
In Spring, bean scope controls how many instances of a bean Spring creates and how long those instances live. By default, Spring beans are singleton scoped, meaning Spring creates one shared instance per ApplicationContext. Common Spring Bean Scopes Scope Meaning singleton One shared instance per Spring container prototype A new instance every time the bean […]
SPRING / CATATAN</>↗Spring02 Jul 2026
Use constructor injection by declaring your dependency as a private final field and accepting it as a constructor parameter. Spring will create the dependency bean and pass it into the constructor automatically. Example: import org.springframework.stereotype.Component; @Component public class MyDependency { public void doSomething() { System.out.println("Dependency logic executed."); } } import org.springframework.stereotype.Service; @Service public class MyService […]
SPRING / CATATAN</>↗Spring02 Jul 2026
Short Answer Use these annotations according to the role of the class: Annotation Use for Typical layer @Component Generic Spring-managed class Utility/infrastructure/helper @Service Business logic Service layer @Repository Data access / persistence Repository/DAO layer All three make the class a Spring bean, meaning Spring can create it, manage it, and inject it into other beans. […]
SPRING / CATATAN</>↗Spring02 Jul 2026
The Spring ApplicationContext is the central runtime container of a Spring application. In simple terms: ApplicationContext is the object that holds your Spring application together. It knows: which objects Spring should manage how those objects are created how dependencies are injected which configuration values are available which beans need lifecycle callbacks which features like transactions, […]
SPRING / CATATAN</>↗Spring02 Jul 2026
Component scanning is how Spring automatically finds your classes and registers them as beans. Instead of manually creating every bean, you annotate classes with Spring stereotypes like: @Component @Service @Repository @Controller @RestController Then Spring scans selected packages, finds those classes, creates bean instances, and makes them available for dependency injection. 1. Basic Example import org.springframework.stereotype.Service; […]