简体   繁体   English

与此 bean 配置等效的 xml 是什么,其中传递了没有定义 bean 配置的 object?

[英]What is the xml equivalent of this bean configuration where an object is being passed for which there is no bean configuration defined?

I need to add OAuth client to a Spring 3 project.我需要将 OAuth 客户端添加到 Spring 3 项目中。 I need to use xml based configuration.我需要使用基于 xml 的配置。 And I want to know the xml equivalent of the following bean configuration I found in another Spring project.我想知道我在另一个 Spring 项目中找到的以下 bean 配置的 xml 等效项。 Note that there is an input parameter in the bean definition where an object of type OAuth2ClientContext is being passed (OAuth2ClientContext is an Interface) and is named clientContext.请注意,bean 定义中有一个输入参数,其中传递了 OAuth2ClientContext 类型的 object(OAuth2ClientContext 是一个接口)并命名为 clientContext。 But no bean definition is written anywhere for clientContext.但是没有为 clientContext 编写任何 bean 定义。 What does this mean?这是什么意思? And how would you write this in xml?你会如何在 xml 中写这个?

@Bean
public OAuth2RestTemplate oauth2RestTemplate(OAuth2ClientContext clientContext){
     return new OAuth2RestTemplate(oauth2Resource(), clientContext);
}

The configuration should be like this配置应该是这样的

<bean id="client" class="package.OAuth2ClientContext" />
<bean id="resource" class="package.Oauth2Resource" />
<bean id="restTemplate" class="package.Oauth2Resource">
    <property name="nameOfPropertyResource" ref="resource" />
    <property name="nameOfPropertyClient" ref="client" />
</bean>

are you sure that the bean client is not declared?你确定没有声明bean客户端吗? Maybe it's declared in some jar?也许它在某些 jar 中声明? If yes you should find it's name and use the name in the ref如果是,您应该找到它的名称并在 ref 中使用该名称

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM