1. 程式人生 > >spring 建構函式注入

spring 建構函式注入

 構造引數為物件時通過 ref bean 指定值.為基本型別是 通過 value 直接賦值

參見下例:

	<bean id="oauthresource" class="org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails">
		<property name="accessTokenUri" value="${com.iwintall.security.client.checkTokenEndpointUrl}" />
		<property name="clientId" value="${com.iwintall.security.client.clientId}" />
		<property name="clientSecret" value="${com.iwintall.security.client.clientSecret}" />
	</bean>
	
	
	<bean id="atr" class="org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest" />
	<bean id="oauthcontext" class="org.springframework.security.oauth2.client.DefaultOAuth2ClientContext">
		<constructor-arg name="accessTokenRequest">
        	<ref bean="atr" />
        </constructor-arg>
	</bean>
	
	
	<bean id="oauth2RestTemplate"  class="org.springframework.security.oauth2.client.OAuth2RestTemplate" >
        <constructor-arg name="resource">
        	<ref bean="oauthresource" />
        </constructor-arg>
        <constructor-arg name="context">
        	 <ref bean="oauthcontext" />
        </constructor-arg>
    </bean>