반응형 Spring22 [Spring] DI(Dependency Injection) 의존성 주입 DI(의존성주입)이란 클래스간의 의존관계를 외부에서 주입해주는것을 의미합니다 아래코드와 같이 TestService 클래스에 간단한 덧셈 메서드가 있습니다 public class TestService { public int sum(int a , int b) { return a+b; } } 이 메서드를 TestController 클래스에서 사용한다고 하면 아래와 같이 됩니다 public class TestController { private final TestService testService; public TestController(TestService testService) { this.testService = testService; } public int sum(int a, int b) throws E.. 2023. 2. 15. [Spring] IoC 와 Bean Spring에서 Bean이란 Spring IoC 컨테이너에서 관리하는 자바 객체를 의미합니다. 일반적으로 Bean을 생성하는 방법은 아래 두가지가 있습니다 1) 직접 Bean 등록방법 @Configuration public class TestConfiguration { @Bean public Test test() { return new Test(); } } 2) Component Scan을 이용한 Bean 등록 import org.springframework.stereotype.Component; @Component public class Test { } 위의 두번째 방법을 이용할때 @Controller, @Service, @Repository 등의 어노테이션도 Bean으로 등록됩니다. 그 이유는 해당 .. 2023. 2. 14. 이전 1 ··· 3 4 5 6 다음 반응형