gpt4 book ai didi

java - 不同主题的 Spring mvc ResourceBundleMessageSource

转载 作者:行者123 更新时间:2023-12-01 15:40:04 25 4
gpt4 key购买 nike

我配置了 appstrings.properties 文件,其中包含与我的应用程序使用的主题相关的字符串。我的应用程序有两个主题。两者都有自己的 appstrings.properties 文件,位于 WEB-INF/strings/theme1/appstringsWEB-INF/strings/theme2/appstrings 。我在 config.properties 文件中指定了属性 themeName。

这是我的 spring 配置文件:

<context:property-placeholder location="file:///${config.properties}" />

...

<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource"
p:basenames="WEB-INF/strings/theme1/appstrings" />

现在我的所有应用程序字符串都来自 WEB-INF/strings/theme1/appstrings.properties 文件。我怎样才能使它动态。即当我将 themeName 属性更改为 theme2 时,它应该从 WEB-INF/strings/theme2/appstrings.properties 获取字符串

最佳答案

您需要使用ResourceBundleThemeSource

<!-- resolves localized <theme_name>.properties files in the classpath to 
allow for theme support -->
<bean
class="org.springframework.ui.context.support.ResourceBundleThemeSource"
id="themeSource" />
<mvc:interceptors>
<bean class="org.springframework.web.servlet.theme.ThemeChangeInterceptor"/>
</mvc:interceptors>

参见Spring Reference Chapter 15.7 Using Themes

对于运行示例,您可以快速创建一个小型 Spring Roo 应用程序。它使用主题支持来更改 css 文件。

关于java - 不同主题的 Spring mvc ResourceBundleMessageSource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8208173/

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