简体   繁体   中英

Hibernate database password at runtime

有没有办法在运行时请求数据库密码而不是将其(加密或不加密)放在hibernate.cfg.xml文件中?

Just about every configuration option in Hibernate has a corresponding method on the object being configured. In reality, the configuration is really just a way to bind XML to the objects being set up. See this article for more information: http://docs.jboss.org/hibernate/core/3.3/reference/en/html/session-configuration.html

That said, the onus is on you to collect the password at startup. That can be the most difficult part of the problem. Once you've collected the password, send it to the appropriate property.

Usually the best way to do it, if you're using a Java EE app server, is to use a JNDI look up to get the database connection instead of using a driver manager. That way the person who sets up the JNDI connection pool is the only one that has to know the password, and it's generally encrypted in the admin console so it's safe.

我想如果您正在使用Hibernate配置的编程实例化,您可以从不包含密码的配置文件初始化它,在您要实例化的配置对象上设置数据库连接的附加属性,然后调用buildConfguration() 。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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