【问题标题】:How I can do to read the tag value for my persistence.xml <jta-data-source> in from a file config.properties如何从文件 config.properties 中读取我的 persistence.xml <jta-data-source> 的标签值
【发布时间】:2012-06-25 21:24:35
【问题描述】:

我想做这样的事情:

config.properties:

dsname=value;
anotherValue=anotherValue;

persitence.xml

<jta-data-source>${dsname}</jta-data-source>

【问题讨论】:

  • 这些文件是否与任何库一起使用,或者您会直接从 java 代码中读取它们吗?
  • 问题是什么?什么不起作用?

标签: java properties config persistence.xml


【解决方案1】:

属性文件在我的 Web 项目之外,我正在将 JPA 与 EclipseLink 一起使用,但我需要从外部文件值“dsname”初始化参数 jta-data-source

其实:

<persistence-unit name="Unit-ejbPU" transaction-type="JTA">
  <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>datasource</jta-data-source>
      <class>Clase1</class>
      <class>Clase2</class>
      <class>Clase3</class>
  <properties/>
</persistence-unit>

构思:

<persistence-unit name="Unit-ejbPU" transaction-type="JTA">
  <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>${dsname}</jta-data-source>
      <class>Clase1</class>
      <class>Clase2</class>
      <class>Clase3</class>
  <properties/>
</persistence-unit>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-02
    • 1970-01-01
    • 2015-02-23
    • 1970-01-01
    • 1970-01-01
    • 2021-08-16
    • 2019-01-02
    • 2015-09-26
    相关资源
    最近更新 更多