learn/spring 8

어노테이션(Annotation) - Spring Boot 관련

@SpringBootApplication 스프링 부트 애플리케이션을 시작할 때 사용 @SpringBootApplication public class MyApplication { public static void main(String[] args) { SpringApplication.run(MyApplication.class, args); } } @RestController RESTful 웹 서비스에서 JSON 또는 XML 형식의 응답을 반환 @Controller와 @ResponseBody 어노테이션의 조합으로 구성 @RestController public class MyRestController { @GetMapping("/hello") public String hello() { return "Hello..

learn/spring 2023.09.26

어노테이션(Annotation) - Spring MVC 관련

@Controller 클래스를 컨트롤러로 지정하고 컨트롤러는 클라이언트의 요청을 처리하고 응답을 생성 @Controller public class MyController { // Controller methods here } @RequestMapping 요청 URL과 메서드를 매핑하여 특정 URL에 대한 요청을 처리할 메서드를 지정 @Controller @RequestMapping("/myapp") public class MyController { @RequestMapping("/home") public String home() { return "index"; } } @GetMapping / @PostMapping HTTP GET 및 POST 요청에 대한 처리를 정의 @Controller @Request..

learn/spring 2023.09.26

어노테이션 (Annotation) - AOP(Aspect-Oriented Programming) 관련

AOP는 애플리케이션의 횡단 관심사(종단 관심사가 아닌 부분)를 모듈화하고 관리하여 주로 다수의 클래스나 모듈에 걸쳐 반복되는 기능을 분리하고 재사용 가능한 모듈로 만드는 데 사용 @Aspect Aspect 클래스를 정의할 때 사용되며, 횡단 관심사를 구현한 클래스 import org.aspectj.lang.annotation.Aspect; @Aspect public class MyAspect { // Aspect 클래스 정의 } @Before 메서드 실행 전에 어드바이스를 실행 import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; @Aspect public class MyAspect { @Before("..

learn/spring 2023.09.26

어노테이션(Annotation) - 설정(Configuration) 관련

설정(Configuration) 관련 @Configuration 해당 클래스가 Spring Bean 구성 정보를 포함하고 있음을 나타냄 @Configuration을 클래스에 적용하고 @Bean을 method에 적용하여 @Autowired로 Bean 사용 @Configuration public class AppConfig { @Bean public MyService myService() { return new MyService(); } @Bean public MyRepository myRepository() { return new MyRepository(); } } @Service public class MyService { private final MyRepository myRepository; @Aut..

learn/spring 2023.09.21

어노테이션(Annotation) - 의존성 주입(Dependency Injection) 관련

의존성 주입(Dependency Injection) 관련 @Autowired 의존성 주입(Dependency Injection)을 수행 필드 주입(Field Injection) 생성자 주입(Constructor Injection) Setter 메서드 주입(Setter Method Injection) //필드 주입(Field Injection) @Service public class UserService { @Autowired private UserRepository userRepository; // ... } //생성자 주입(Constructor Injection) @Service public class UserService { private final UserRepository userRepositor..

learn/spring 2023.09.21

어노테이션(Annotation) - 컴포넌트 스캔(Component Scan) 관련

컴포넌트 스캔(Component Scan) 관련 자바 코드에 메타데이터를 부여하여 해당 코드의 동작 방식을 정의하거나 특정 기능을 활성화하는 데 사용되는 특별한 주석 형태의 요소. 클래스, 메서드, 필드 등과 같은 다양한 요소에 적용할 수 있으며, 애플리케이션을 설정하고 관리 Annotations are special comment-like elements used in Java code to provide metadata, define the behavior of the code, or activate specific functionalities. They can be applied to various elements such as classes, methods, fields, and more. Ann..

learn/spring 2023.09.21

빈 (Bean)

빈 (Bean) Spring에서 애플리케이션의 핵심을 이루고 Spring IoC 컨테이너에 의해 관리되는 객체를 빈(Bean)이라 함. 빈은 Spring IoC 컨테이너에 의해 인스턴스화되고 조립되며 관리되는 객체임. In Spring, the objects that form the backbone of your application and that are managed by the Spring IoC container are called beans. A bean is an object that is instantiated, assembled, and otherwise managed by a Spring IoC container. Java 클래스를 Bean으로 선언하기 위해 @Component, @Ser..

learn/spring 2023.09.21

스프링 컨테이너 (Spring Container)

스프링 컨테이너 (Spring Container) 스프링 컨테이너는 Spring에서 빈(Bean)들의 생명주기를 관리하는 Spring Framework의 코어(Core)이다. The Spring container is the core of the Spring Framework, responsible for managing the lifecycle of beans and facilitating dependency injection. Bean 객체의 생성과 소멸 관리 Bean 객체 간의 의존성 주입(Dependency Injection) 설정 정보를 통한 Bean 객체의 설정과 구성 Bean을 Singleton으로 관리하므로 여러 곳에서 동일한 Bean 인스턴스를 공유 AOP를 통해 관점 지향 프로그래밍을 ..

learn/spring 2023.09.19