hibernate.cfg.xml-从属性文件设置参数 [英] hibernate.cfg.xml - Set parameters from a properties file

查看:50
本文介绍了hibernate.cfg.xml-从属性文件设置参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个文件 hibernate.cfg.xml ,该文件用于在sturtup上配置hibernate.

I've this file hibernate.cfg.xml that I use to configure hibernate at sturtup.

<property name="hibernate.connection.username">dbUser</property>
<property name="hibernate.connection.password">1234</property>

我有一个名为 config.properties 的属性文件,其中包含应用程序中使用的所有其他配置.

I've a properties file that it's called config.properties that hold all other configurations used into the application.

如何从属性文件(config.properties)中设置"hibernate.connection.username" 参数,这样我只能编辑一个文件?

How can I set "hibernate.connection.username" parameter from the properties file (config.properties) so I have only one file to edit?

推荐答案

对我来说,解决方案是在运行时向配置中添加属性:

The solution for me is that, Adding a properties at runtime into the configuration:

configuration.setProperty("hibernate.connection.username", Config.db.getUser());

这篇关于hibernate.cfg.xml-从属性文件设置参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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