【发布时间】:2013-12-31 11:43:33
【问题描述】:
我正在尝试覆盖单元测试的数据源配置,如下所述:
但我面临一些警告,并且某些属性没有正确考虑:
Infos - Cannot find the configuration file [conf/openejb.xml]. Will attempt to create one for the beans deployed.
Infos - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
Infos - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
Infos - Configuring Service(id=customDS, type=Resource, provider-id=Default JDBC Database)
Infos - Creating TransactionManager(id=Default Transaction Manager)
Infos - Creating SecurityService(id=Default Security Service)
Infos - Creating Resource(id=customDS)
WARNING - Property "JdbcUsername " not supported by "customDS"
WARNING - Property "JdbcPassword " not supported by "customDS"
WARNING - Property "JdbcUrl " not supported by "customDS"
WARNING - Property "JdbcDriver " not supported by "customDS"
我的自定义 DS 配置如下:
Properties p = new Properties();
// Datasource
p.put("customDS", "new://Resource?type=javax.sql.DataSource");
p.put("customDS.JdbcDriver ", "org.hsqldb.jdbc.JDBCDriver");
p.put("customDS.JdbcUrl ", "jdbc:hsqldb:file:target/custom");
p.put("customDS.JdbcUsername ", "sa");
p.put("customDS.JdbcPassword ", "");
// JPA
p.put("javax.persistence.jtaDataSource", "openejb:Resource/customDS");
// EclipseLink
p.put("competbet.eclipselink.target-database", "org.eclipse.persistence.platform.database.HSQLPlatform");
p.put("competbet.eclipselink.ddl-generation", "create-or-extend-tables");
context = EJBContainer.createEJBContainer(p).getContext();
非测试配置工作正常:
<resources>
<Resource id="JTA_Datasource" type="javax.sql.DataSource">
# http://tomee.apache.org/containers-and-resources.html
# configure the pool
DataSourceCreator = ${bd.datasourceCreator}
# it is a jta datasource
JtaManaged = true
# tomcat pool configuration
driverClassName = ${bd.driver}
url = ${bd.url}
username = ${bd.username}
password = ${bd.password}
validationQuery = ${bd.validationQuery}
# specific to tomcat pooling
jmxEnabled = true
</Resource>
</resources>
知道如何让我的自定义 DS jdbc 属性适用于我的单元测试吗?
【问题讨论】:
标签: java jpa datasource apache-tomee openejb