티스토리 뷰
0. 스프링 부트가 아닌 스프링의 기본적인 기동을 위해서는 core와 context 모듈이 필요하다.
0-1 스프링 설정에는 3가지 방법이 있다.
0-2-1 첫번째는 여기에서 설명하고 있는 Full XML Configuration로 아래와 같은 방법이다.
0-2-2 두번째는 XML with Component Scan인데
0-2-2-1 이 방법은 xml을 기본으로 사용하지만
0-2-2-2 bean생성을 @Component annotation과 component scan으로 한다.
0-2-2-3 dependency injection을 @Autowired로 처리한다.
0-2-3 세번째는 Java Configuration Class로 한다. 이 경우는 XML이 완전히 필요없다.
1. spring xml configuration은 상당히 불편하다.
1-0기본적으로 applicationContext.xml 파일이 필요하다.
1-0-1 아래는 기본적인 설정 파일이다. 기본적으로 복사해서 사용하는 것이 편리하다.
1-1. 아래 코드는 기본코드에 여러가지가 추가되어 있다.
1-1-1 property-placeholder는 외부파일에서 속성을 읽어오는 설정이다.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder location="classpath:pilseong.properties"/>
<!-- to set this logger you have to define in the very beginning of xml file and
set the init-method to trigger initializtion -->
<bean id="myLoggerConfig" class="pe.pilseong.ioc.util.MyLoggerConfig" init-method="initLogger">
<property name="rootLoggerLevel" value="FINE"></property>
<property name="printedLoggerLevel" value="FINE"></property>
</bean>
<bean id="goodFortuneService" class="pe.pilseong.ioc.coaches.GoodFortuneService"></bean>
<bean id="baseballCoach" class="pe.pilseong.ioc.coaches.BaseballCoach">
<property name="fortuneService" ref="goodFortuneService"></property>
<property name="email" value="${pilseong.email}"></property>
<property name="address" value="${pilseong.address}"></property>
</bean>
<bean id="footballCoach" class="pe.pilseong.ioc.coaches.FootballCoach">
<constructor-arg ref="goodFortuneService"></constructor-arg>
<property name="emailAddress" value="heops79@gmail.com"></property>
<property name="salary" value="100000"></property>
</bean>
</beans>
Dependency Injection - 위의 소스코드 참조
1. constuctor based injection - constructor-arg 태그를 사용한다.
2. setter based injection - property 태그를 사용하되 객체는 ref로 참조한다.
3. value injection의 경우는 property 태그를 사용하되 value로 값을 제공한다.
4. properties 파일로부터 읽어 올 경우 - 아래 소스 참조
4-1 읽어올 속성 파일을 classpath 경로에 만든다.
4-2. xml 설정파일의 앞부분에 context property-placehoder 태그를 사용하여 파일을 지정한다.
4-3. 실제 값 입력 부분에 ${}를 사용하여 속성을 지정한다. {} 안은 공백을 허용하지 않는다.
<!-- 아래 코드는 속성 파일을 읽어오는 부분이다. -->
<context:property-placeholder location="classpath:pilseong.properties"/>
<!-- 아래 코드는 읽어온 파일의 속성을 사용하는 부분이다. -->
<!-- 여기서 중요한 부분은 ${}로 속성 이름을 가져오는데 안에 공백이 들어가면 안된다. -->
<bean id="baseballCoach" class="pe.pilseong.ioc.coaches.BaseballCoach">
<property name="fortuneService" ref="goodFortuneService"></property>
<property name="email" value="${pilseong.email}"></property>
<property name="address" value="${pilseong.address}"></property>
</bean>
실제 pilseong.properties파일은 지정형식은 아래 내용처럼 담기게 된다.
pilseong.email=heops79@gmail.com
pilseong.address=siminro66beangil 21
'Spring > Spring Basic' 카테고리의 다른 글
Spring : Web MVC - Request parameter 받기 (0) | 2020.04.22 |
---|---|
Spring : Web MVC with XML configuration (0) | 2020.04.22 |
Spring : Configuration with Java Config Class - 설정 및 외부 properties 에서 읽어오기 (0) | 2020.04.22 |
Spring : Configuration with XML configuration + Spring Annotations + @Qualifier (0) | 2020.04.22 |
Spring : Bean Scope and Bean Lifecycle (0) | 2020.04.22 |
- Total
- Today
- Yesterday
- 도커 개발환경 참고
- AWS ARN 구조
- Immuability에 관한 설명
- 자바스크립트 멀티 비동기 함수 호출 참고
- WSDL 참고
- SOAP 컨슈머 참고
- MySql dump 사용법
- AWS Lambda with Addon
- NFC 드라이버 linux 설치
- electron IPC
- mifare classic 강의
- go module 관련 상세한 정보
- C 메모리 찍어보기
- C++ Addon 마이그레이션
- JAX WS Header 관련 stackoverflow
- SOAP Custom Header 설정 참고
- SOAP Custom Header
- SOAP BindingProvider
- dispatcher 사용하여 설정
- vagrant kvm으로 사용하기
- git fork, pull request to the …
- vagrant libvirt bridge network
- python, js의 async, await의 차이
- go JSON struct 생성
- Netflix Kinesis 활용 분석
- docker credential problem
- private subnet에서 outbound IP 확…
- 안드로이드 coroutine
- kotlin with, apply, also 등
- 안드로이드 초기로딩이 안되는 경우
- navigation 데이터 보내기
- 레이스 컨디션 navController
- raylib
- 하이버네이트
- crud
- 스프링
- 스프링부트
- login
- mapping
- Validation
- WebMvc
- Spring Security
- XML
- MYSQL
- 설정
- RestTemplate
- spring boot
- one-to-many
- 상속
- 로그인
- Security
- 자바
- hibernate
- form
- 외부파일
- Rest
- 매핑
- 설정하기
- Angular
- jsp
- one-to-one
- Many-To-Many
- Spring