Spring El 表达式

发布于 2024-09-10 08:54:01 字数 265 浏览 0 评论 0原文

我正在从 faces-config 切换到 Spring,想知道如何将属性从一个 bean 传递到另一个 bean:

例如

<bean id="myBean" class="Bean1">

 </bean>
 <bean id="myBean2" class="Bean2">
    <constructor-arg ref="#{myBean1.value}"/>
 </bean>

I'm switching from faces-config to Spring and wanted to know how you can pass a property from one bean to another:

e.g.

<bean id="myBean" class="Bean1">

 </bean>
 <bean id="myBean2" class="Bean2">
    <constructor-arg ref="#{myBean1.value}"/>
 </bean>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绝不放开 2024-09-17 08:54:01

升级到Spring 3.0,支持spring el

Upgraded to Spring 3.0 which has spring el support

千里故人稀 2024-09-17 08:54:01

首先,DI 容器的目的是在执行之前完全初始化您的系统;也就是说,所有依赖项都已设置,应用程序就可以运行了。

Spring 中有 @property 和 @value 注释用于类似的目的,但由于您想使用其他 bean 的特定 bean 属性值,最好的解决方案是:

<bean id="myBean" class="Bean1">

 </bean>
 <bean id="myBean2" class="Bean2">
    <constructor-arg ref="myBean"/>
 </bean>

如果您认为只想在实例化时设置值,并且不建立依赖关系,则跳过DI部分,直接设置值。

First things first, the purpose of the D.I container is to fully initialize your system prior to execution; that is, all dependencies being set, the app is ready to run.

There are both @property and @value annotations in Spring for similar purposes, but since you want to use and specific bean property value for other bean the best solution would be:

<bean id="myBean" class="Bean1">

 </bean>
 <bean id="myBean2" class="Bean2">
    <constructor-arg ref="myBean"/>
 </bean>

If you argue that you just want to set the value at instantiation time, and not establish a dependency, then skip the D.I part and set the value directly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文