2014-04-22 30 views
3

構造函數參數,該參數是正確的方式來翻譯這個bean:春:豆作爲Java的配置

<bean id="artifactBinding" class="org.springframework.security.saml.processor.HTTPArtifactBinding"> 
    <constructor-arg ref="parserPool"/> 
    <constructor-arg ref="velocityEngine"/> 
    <constructor-arg> 
     <bean class="org.springframework.security.saml.websso.ArtifactResolutionProfileImpl"> 
      <constructor-arg> 
       <bean class="org.apache.commons.httpclient.HttpClient"> 
        <constructor-arg> 
         <bean class="org.apache.commons.httpclient.MultiThreadedHttpConnectionManager"/> 
        </constructor-arg> 
       </bean> 
      </constructor-arg> 
      <property name="processor"> 
       <bean class="org.springframework.security.saml.processor.SAMLProcessorImpl"> 
        <constructor-arg ref="soapBinding"/> 
       </bean> 
      </property> 
     </bean> 
    </constructor-arg> 
</bean> 

<bean id="soapBinding" class="org.springframework.security.saml.processor.HTTPSOAP11Binding"> 
    <constructor-arg ref="parserPool"/> 
</bean> 

從XML到Java的配置?

+0

你提到的工廠方法在哪裏? – geoand

+0

對不起,這裏沒有任何工廠方法。 – vdenotaris

+0

好的,沒問題! – geoand

回答

3

您也可以通過形成

@Bean 
public HTTPArtifactBinding artifactBinding(ParserPool parserPool, VelocityEngine velocityEngine) { 
    return new HTTPArtifactBinding(parserPool, velocityEngine, artifactResolutionProfile()); 
} 

縮小所需的合作者對象的範圍。如果春天可以解決parserPool和velocityEngine話,就可以注入到你的@Bean高清方法。

0
@Configuration 
public class Configuration { 

    @Autowired 
    private ParserPool parserPool; 

    @Autowired 
    private VelocityEngine velocityEngine; 

    @Bean 
    public HTTPArtifactBinding artifactBinding() { 
     return new HTTPArtifactBinding(parserPool, velocityEngine, artifactResolutionProfile()); 
    } 

    private ArtifactResolutionProfile artifactResolutionProfile() { 
     final ArtifactResolutionProfile artifactResolutionProfile = new ArtifactResolutionProfile(new HttpClient(new MultiThreadedHttpConnectionManager())); 
     artifactResolutionProfile.setProcessor(new SAMLProcessorImpl(soapBinding())); 
     return artifactResolutionProfile; 
    } 

    @Bean 
    public HTTPSOAP11Binding soapBinding() { 
     return new HTTPSOAP11Binding(parserPool); 
    } 
}