[Spring] Component, property 중 누가 더 힘이 셀까

탱귤생귤·2023년 9월 12일

Spring

목록 보기
4/14
<context:component-scan base-package="com.ssafy.ws"></context:component-scan>
	<!-- bean태그를 이용하여 직접 등록 -->
	<bean class="com.ssafy.ws.K3" id="k3"/>
	<bean class="com.ssafy.ws.Sonata" id="sonata"/>
	<bean class="com.ssafy.ws.Driver" id="driver">
		<property name="car" ref="k3"></property>
	</bean>

이렇게 하면

이렇게 뜨고

<!-- bean태그를 이용하여 직접 등록 -->
	<bean class="com.ssafy.ws.K3" id="k3"/>
	<bean class="com.ssafy.ws.Sonata" id="sonata"/>
	<bean class="com.ssafy.ws.Driver" id="driver">
		<property name="car" ref="k3"></property>
	</bean>
	
	<context:component-scan base-package="com.ssafy.ws"></context:component-scan>
	

이렇게 하면

이렇게 나옴

둘은 괜찮은듯

근데 실행을 하면 무조건 property에 등록된 게 실행됨

property가 가장 쎈 것으로 결론냄

그리고 중복으로 등록하고 이름도 동일해도 오류가 나지 않는 점이 특이했다.

0개의 댓글