목록Spring (33)
wintertreey 님의 블로그
AOP의 핵심기능, 부가기능 애플리케이션 로직은 크게 핵심 기능과 부가 기능으로 나눌 수 있다. 핵심 기능 Core Concerns : 해당 객체가 제공하는 고유의 기능. 부가 기능 Cross-cutting Concerns : 핵심 기능을 보조하기 위해 제공되는 기능 ( ex: 로그 추적 기능, 트랜잭션 기능 )보통 기존 프로젝트에 부가 기능을 추가하게 되면, 그림처럼 하나의 클래스가 아닌 여러 클래스에 부가 기능을 추가하게 된다. 예를 들어서 프로젝트의 모든 클래스에 로그 기능을 추가 한다고하면, 하나의 부가 기능(로그 추적)을 여러 곳에 동일하게 사용하게 된다. AOP란?Aspect Oriented Programming 관점 지향 프로그램 객체지향의 기본원칙(OOP)으로는 핵심기능에서 부가기능을 분리..
@Qualifier@autowired 타입으로 매핑!@Autowired private SenderInter senderInter;라고 해주고 sender, sender2 둘다 인터페이스해주면 expected single matching bean but found 2: sender,sender2라고 에러문구가 뜬다. 인스턴스된 객체가 두개라 에러가 떨어지는것. 해결방법 :@Qualifier("sender")센더인터타입이 두갠데, 그중에 센더와 매핑한다는것.즉 퀄리파이어는 오토와이어드의 보조어노테이션 @Resource @Resource는 @Autowired와 달리 객체변수이름으로 매핑을 한다. pojo란?POJO란 Plain Old Java Object의 약자로, 이를 직역하면 순수한 오래된 자바 객체..
@Scope("Singleton") vs @Scope("prototype")스코프의 기본값이 싱글톤인건 앞서 공부했다. 그렇다면 프로토타입, 싱글톤은 어떤 상황에서 구분해서 사용할 수 있을까 Bank.javapackage pack.bank;public interface Bank { void inputMoney(int money); //입금 void outputMoney(int money); //출금 int getMoney(); //잔고확인}HanaBank.javapackage pack.bank;import org.springframework.context.annotation.Scope;import org.springframework.stereotype.Component;@Component//@Scope(..
이번에는 Constructor Injection, Setter Injection 모두 적용시켜보자. Sum up! 기본 작업pom.xml - maven 작업. dependencies 넣어주기 분류작업을 위해 package model, controller, other를 만들어주었다. Model 부터 시작인터페이스 & 클라스 생성하기. MyInfoInter.javapackage pack.model;public interface MyInfoInter { String myData();} MyInfo.javapackage pack.model;public class MyInfo implements MyInfoInter { @Override public String myData() { return "취미는 ..
우리가 Spring을 사용하는 수 많은 이유중에 대표적인 장점을 꼽으라면 의존성 주입 컨테이너에 관한 내용을 빼놓을 수 없다. 스프링은 자바 빈을 찾아서 ApplicationContext라고 하는 의존성 주입 컨테이너 오브젝트에 등록을 한다. 그리고 애플리케이션이 돌다가 어떤 오브젝트가 필요하다면 의존하는 오브젝트를 찾아서 연결해준다. 그렇다면 스프링은 어떻게 자바 빈을 찾아가지고 의존성 주입 컨테이너에 등록하는걸까?? @Component 어노테이션으로 이 클래스를 자바 빈으로 등록하라고 알려줄 수 있다. @Component@Component 어노테이션을 붙이면 이 클래스를 자바 빈으로 등록시키라고 알려줄 수 있다. 해당 어노테이션이 명시되어 있으면 Spring이 자동으로 클래스의 인스턴스를 생성해준다...
앞서 constructor injection에 대해서 실습해보았다. 이번엔 setter injection. 생성자의 경우 객체생성을 1번만 할 수있다.그에 반해 setter의 경우 생성자보다 더 유연하다는 장점이 있다. 연습pom.xmlmaven 프로젝트이기에 dependency 부분 추가해서 넣어준다. ShowData.javapackage pack;public class ShowData { public String processNickName() { return "홍길동"; } public String processHobby() { return "프로그래밍 만들기"; }} MyProcess.javapackage pack;public class MyProcess { //DI 중 setter i..
다형성(Polymorphism)은 객체지향 프로그래밍의 중요한 개념 중 하나로, 같은 코드가 여러 가지 형태로 동작할 수 있는 특성. 이는 코드의 재사용성과 유연성을 높여주는 중요한 원리이다. 다형성의 종류와 설명메서드 오버라이딩 (Method Overriding):서브클래스(자식 클래스)가 슈퍼클래스(부모 클래스)의 메서드를 재정의하여 사용하는 것을 말한다. 이 경우에는 서브클래스에서 같은 이름의 메서드를 정의하면 슈퍼클래스의 메서드는 숨겨지고 서브클래스에서 정의한 메서드가 호출된다.메서드 오버로딩 (Method Overloading):같은 이름의 메서드를 매개변수의 타입이나 개수를 다르게 하여 여러 개 정의하는 것. 컴파일러가 메서드 호출 시 전달되는 인자에 따라 적절한 메서드를 선택.다형적 변수 (..
이 개념들을 완전히 지금 다 이해할수는 없을 것이다. 간단히 의미정도만 확인하고 넘어가자. 스프링 vs 스프링 부트Spring은 스프링 프레임워크의 핵심 모듈을 모아서 만든 프레임워크 Spring에서는 개발자가 직접 설정 파일을 작성하여 스프링 컨테이너를 구성하고, 필요한 빈 객체를 등록하고, 빈 객체 간의 의존성을 설정해야 한다. Spring은 특정한 구성을 위해 추가적인 라이브러리와 설정이 필요.반면, Spring Boot는 스프링 프레임워크를 보다 쉽게 사용할 수 있도록 만든 프레임워크. Spring Boot에서는 개발자가 설정 파일을 작성할 필요 없이, 프로젝트의 설정과 라이브러리 의존성을 자동으로 처리해주는 기능을 제공. 또한, Spring Boot는 실행 가능한 JAR 파일을 만들 수 있다...