JAVA

Spring - DI 의존성 주입 dependency injection

곰탁 2022. 3. 7. 16:49

DI 적용 X

@restcontroller
public class mycontroller {
    private myservice service = new myservice();

    @requestmapping("/welcome")
    public string welcome() {
        return service.retrievewelcomemessage();
    }
}

DI 예시

@component
public class myservice {
    public string retrievewelcomemessage(){
       return "welcome to innovationm";
    }
}
@restcontroller
public class mycontroller {

    @autowired
    private myservice service;

    @requestmapping("/welcome")
    public string welcome() {
        return service.retrievewelcomemessage();
    }
}

 

DI는 코드간 결합도를 낮춘다.

 

임시

 

 

https://dzone.com/articles/spring-vs-spring-boot

 

Spring vs. Spring Boot: A Comparison of These Java Frameworks - DZone Java

In this post, we compare and contrast the two most popular Java frameworks — Spring and Spring Boot — to demonstrate the types of problems that they solve.

dzone.com