简体   繁体   English

在Spring XML配置文件中连接字符串?

[英]Concatenate strings within a Spring XML configuration file?

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: 我在Spring配置文件中有一个String值,它是JNDI查找的结果 - 它恰好是一个路径名:

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

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): 现在我需要在此路径的末尾连接另一个字符串并将其交给另一个Spring bean,如下所示(当然这不起作用):

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

Is there a simple way to do this without me having to write a utility class in Java? 有没有一种简单的方法可以在不用Java编写实用程序类的情况下执行此操作?

Try using Spring EL (expression language) . 尝试使用Spring EL(表达式语言) 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>

Not quite sure if it would work. 不太确定它是否有效。 The thing that troubles me is the cast from File (I guess) to String when concatenating. 困扰我的是连接时从File(我猜)到String的转换。 So if the previous one didn't work, I would try: 所以,如果前一个不起作用,我会尝试:

#{myAppHomeDir.canonicalPath+'/logs'}

Let us know if it works. 如果有效,请告诉我们。

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

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