我正在尝试覆盖单元测试的数据源配置,如下所述:
但是我面临一些警告,有些属性没有正确考虑:
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属性适用于我的单元测试的任何想法?
答案 0 :(得分:2)
您是否尝试从属性定义中删除空格线?
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"
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 ", "");
我认为这应该有效(没有空格)。
希望这有帮助。
修改强> 的
也许它是您定义数据源的属性:
p.put("customDS", "new://Resource?type=javax.sql.DataSource");
文档指定如下所示:
p.put("customDS = new://Resource?type", "DataSource");
修改强> 的
此处列出了要使用的正确属性:http://tomee.apache.org/containers-and-resources.html
p.put("customDS.JdbcDriver", "org.hsqldb.jdbc.JDBCDriver");
p.put("customDS.JdbcUrl", "jdbc:hsqldb:file:target/custom");
p.put("customDS.UserName", "sa");
p.put("customDS.Password", "");