连接Spring XML配置文件中的字符串? [英] Concatenate strings within a Spring XML configuration file?

查看:1635
本文介绍了连接Spring XML配置文件中的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Spring配置文件中有一个String值,作为JNDI查找的结果 - 它恰好是一个路径名:

I have a String value in a Spring configuration file that comes to be as the result of a JNDI lookup -- it happens to be a path name:

< jee:jndi-lookup id =myAppHomeDirjndi-name =myAppHomeDir/>

我需要连接到这个路径的另一个字符串结束,并交给另一个Spring bean如下(这当然不工作):

Now I need to concatenate on to the end of this path another string and hand it off to another Spring bean as follows (which of course doesn't work):

<bean id="LogPath" class="org.mystuff.initBean">
    <property name="logDirectory">
       <jee:jndi-lookup id="myAppHomeDir"
                 jndi-name="myAppHomeDir" /> + "/logs"
    </property>
</bean>

有没有一个简单的方法可以做到这一点没有我写一个实用程序类Java? p>

Is there a simple way to do this without me having to write a utility class in Java?

推荐答案

尝试使用 Spring EL(表达式语言)。我将尝试以下(未测试):

Try using Spring EL (expression language). I would try the following (not tested):

<jee:jndi-lookup id="myAppHomeDir" jndi-name="myAppHomeDir" />

<bean id="LogPath" class="org.mystuff.initBean">
    <property name="logDirectory" value="#{myAppHomeDir+'/logs'}"/>
</bean>

不太确定如果它可以工作。麻烦我的事情是从File(我猜)转换为字符串时,连接。所以如果前一个没有工作,我会尝试:

Not quite sure if it would work. The thing that troubles me is the cast from File (I guess) to String when concatenating. So if the previous one didn't work, I would try:

#{myAppHomeDir.canonicalPath+'/logs'}

让我们知道它是否有效。

Let us know if it works.

这篇关于连接Spring XML配置文件中的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆