스프링은 싱글톤(singgleton), 프로토타입(prototype), 요청(request), 세션(session), 글로벌세션(globalSession), 애플리케이션(application) 스코프를 기본적으로 제공 스프링에서 별도의 설정 없이 등록한 빈은 모두 싱글톤 빈이다. 요청 스코프 빈이 빈은 하나의 사용자 웹 요청 안에서 만들어지고 요청이 끝나면 제거된다.각 요청별로 독립적인 빈이 만들어지기 때문에 빈 객체 내에 상태유지 값을 저장해 두어도 안전하다.동시에 많은 요청이 있더라도 각각 별도의 요청 스코프 빈이 만들어지기 때문에 안전하다. +리퀘스트 스코프 빈 모델 객체123456789101112131415@Component@Scope("request")public class RequestScop..
기본적으로 스프링에서 빈을 등록하면 싱글톤으로 만들어진다. 애플리케이션 컨텍스트 마다 빈은 한개씩만 만들어진다는 얘기다.사용자의 요청이 있을 때마다 매번 관련 있는 빈을 새로 생성하는 것은 비효율적이기 때문이다. 싱글톤 빈은 의존성 주입(DI)을 하든지 ApplicationContext를 이용해서 빈을 불어와도 매번 같은 객체를 반환한다. 그런데 때로는 빈을 싱글톤이 아닌 하나의 빈으로 여러개의 객체를 만들어 사용해야 할 때가 있다.그럴 때 프로토 타입 빈을 사용하는데 프로토타입 빈은 컨테이너에게 빈을 요청할 때마다 매번 새로운 객체를 생성하여 반환해준다. 싱글톤빈은 다음과 같이 애노테이션으로 설정할 수 있다.12345678910111213@Component@Scope("prototype")public ..
XML에서 빈을 등록했다면 생성자나 자바빈 규약에 따른 수정자(set으로 시작하는 메서드)에 의존관계 빈이나 값을 주입할 수 있다. 1234567891011public class InjectionTest { public InjectionTest(String name, int age, String s) { System.out.println(name + "======" + age + "=========" + s.toString()); } public void setParameterSetting(String a) { System.out.println(a); } }Colored by Color Scriptercs 123456789 Colored by Color Scriptercs스프링 컨텍스트 XML설정 파일에..
스프링에선 객체의 생성과 사용 및 제거 등의 작업을 애플리케이션 소스코드 대신 독립된 컨테이너가 담당한다. 이것을 IoC(제어역전)라고 부르며, 스프링 컨테이너를 IoC컨테이너라고 부른다. IoC컨테이너의 기본적인 역할코드를 대신해서 애플리케이션을 구현하는 오브젝트를 생성하고 관리하는 것 xml문서, 자바코드, 애노테이션 같은 리소스를 통해서 BeanDefinition 인터페이스 타입으로 변환되어져 이 타입을 IoC컨테이너가 활용한다.BeanDefinition에는 bean하나를 만드는데 필요한 여러 가지 정보가 들어있다. bean 등록 방법은 빈에 필요한 메타정보를 작성해서 컨테이너에 설정하면 된다.가장 직접적인 방법은 BeanDefinition타입의 인터페이스를 구현하는 클래스를 직접 생성하는 것이다...
탭을 사용하면 한 화면에서 서로 다른 두가지 화면의 정보를 전환하면서 보여줄 수 있다. 먼저 com.android.support.design라이브러리를 추가한다. File탭 - project structure - app - dependencies에서 (+)추가 버튼을 누른다. 그리고 Library dependency선택 후 해당 라이브러리를 추가한다. 메인 xml파일을 작성한다.12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 Colored by Color Scriptercs 탭을 사용하는 것은 한 액티비비에서 화면이 전..