Spring 자동 조립 Bean 실현 과정 상세 설명
자동 조립 을 사용 하려 면
표 1 autowire 의 속성 과 역할
명칭.
설명 하 다.
byName
Property name 에 따라 자동 으로 설치 되 며,한 Bean 의 name 이 다른 Bean 의 Property name 과 같 으 면 이 Bean 을 Property 에 자동 으로 설치 합 니 다.
byType
Property 의 데이터 형식(Type)에 따라 자동 으로 조립 되 며,한 Bean 의 데이터 형식 이 다른 Bean 의 Property 데이터 형식 과 호 환 되면 자동 으로 조립 됩 니 다.
constructor
구조 방법의 매개 변수 데이터 형식 에 따라 by Type 모드 의 자동 조립 을 진행 합 니 다.
autodetect
기본 구조 방법 이 발견 되면 constructor 모드 를 사용 합 니 다.그렇지 않 으 면 by Type 모드 를 사용 합 니 다.
no
기본 적 인 상황 에서 자동 조립 을 사용 하지 않 고 Bean 의존 은 ref 요 소 를 통 해 정의 해 야 합 니 다.
다음은 사례 를 통 해 자동 조립 을 어떻게 실현 하 는 지 보 여 준다.우선 applicationContext.xml 프로필 을 자동 조립 형식 으로 수정 합 니 다.다음 과 같 습 니 다.
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<bean id="personDao" class="com.mengma.annotation.PersonDaoImpl" />
<bean id="personService" class="com.mengma.annotation.PersonServiceImpl"
autowire="byName" />
<bean id="personAction" class="com.mengma.annotation.PersonAction"
autowire="byName" />
</beans>
위 설정 파일 에 서 는 personService 와 personAction 을 설정 하 는기본적으로 설정 파일 에 서 는 ref 를 통 해 Bean 을 설치 해 야 하지만 autowire="by Name"이 설정 되 어 있 습 니 다.Spring 은 설정 파일 에서 속성 이름 personDao 와 같은
JUnit 을 사용 하여 테스트 클래스 의 test()방법 을 다시 실행 합 니 다.콘 솔 의 표시 결 과 는 그림 과 같 습 니 다.
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
[MeU] Hashtag 기능 개발➡️ 기존 Tag 테이블에 존재하지 않는 해시태그라면 Tag , tagPostMapping 테이블에 모두 추가 ➡️ 기존에 존재하는 해시태그라면, tagPostMapping 테이블에만 추가 이후에 개발할 태그 기반 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.