Created
May 31, 2025 14:52
-
-
Save yoonseohyun0206/95f50c009fe388df843f3f462308a15a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.example; | |
import org.springframework.stereotype.Component; | |
@Component | |
public class ConsolePrinter implements Printer { | |
@Override | |
public void printMessage(String message) { | |
System.out.println("Console : " + message); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.example; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.stereotype.Component; | |
@Component | |
public class FilePrinter { | |
private final Printer printer; | |
@Autowired | |
public FilePrinter(Printer printer) { | |
this.printer = printer; | |
} | |
public void play() { | |
printer.printMessage("Hello World"); | |
System.out.println("파일이 출력됩니다."); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.example; | |
import org.springframework.context.ApplicationContext; | |
import org.springframework.context.annotation.AnnotationConfigApplicationContext; | |
public class Main { | |
public static void main(String[] args) { | |
// IoC 컨테이너 초기화 | |
ApplicationContext context = new AnnotationConfigApplicationContext("org.example"); | |
// Spring container가 관리하는 객체 가져오기 | |
FilePrinter fileprinter = context.getBean(FilePrinter.class); | |
fileprinter.play(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.example; | |
public interface Printer { | |
void printMessage(String message); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment