在 spring-context.xml 和 persistence.xml 中加载 .properties [英] loading .properties in spring-context.xml and persistence.xml

查看:30
本文介绍了在 spring-context.xml 和 persistence.xml 中加载 .properties的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 spring-context.xml 和 JPA persistence.xml 中引用 .properties 文件?

is there a way to reference a .properties file in a spring-context.xml and a JPA persistence.xml?

我想我在 spring 上下文文件中的某个地方看到过这样的例子,尽管我不记得那是在哪里.也许有人知道这个?关于persistence.xml,我实际上不确定这是否有效.

I think I've seen somewhere an example of this in spring context files, though I can't remember where that was. Maybe someone knows this? About the persistence.xml I am actually unsure if this works at all.

我的目标是更改开发和分发配置之间的一些属性.我目前的想法是通过模板配置中的 ant 手动替换文件中的所有属性.虽然应该有更好的方法来做到这一点.:)

My aim is to change some properties between development and distribution configuration. The idea I have currently is to replace all properties manually in the files via ant from a template config. Though there should be a better way to do this. :)

推荐答案

您可以使用 PropertyPlaceholderConfigurer.我认为这不适用于 JPA persistence.xml,尽管 Spring 的 JPA 支持允许您将大部分(如果不是全部)persistence.xml 的内容合并到 bean 文件本身中,在这种情况下它会正常工作.

You can reference external property files from a Spring bean definition file using a PropertyPlaceholderConfigurer. I don't think that will work for a JPA persistence.xml, although Spring's JPA support allows you to incorporate most, if not all, the content of persistence.xml into the beans file itself, in which case it would work fine.

这篇关于在 spring-context.xml 和 persistence.xml 中加载 .properties的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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