gpt4 book ai didi

java - Spring:bean 作为 Java Config 中的构造函数参数

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:48:19 25 4
gpt4 key购买 nike

翻译这个 bean 的正确方法是:

<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-Config?

最佳答案

您还可以通过形成来缩小所需协作者对象的范围

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

如果 Spring 可以解析 parserPool 和 velocityEngine,那么它可以注入(inject)您的 @Bean def 方法。

关于java - Spring:bean 作为 Java Config 中的构造函数参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23215063/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com