【发布时间】:2018-02-08 17:13:49
【问题描述】:
我从 NetBeans 上的 Maven 原型 jersey-quickstart-webapp 创建了一个 Jersey 项目。我正在使用 ActiveJDBC 进行数据持久性。在其文档中,可以参考数据库连接属性的外部文件:http://javalite.io/database_connection_management#location-of-property-file
我已按照说明进行操作,并且我有这个 activejdbc.properties(位于 project-ws/src/main/)文件内容:
env.connections.file=C:\dev\database.properties
还有database.properties 文件:
development.driver=com.mysql.jdbc.Driver
development.username=user_db
development.password=*****
development.url=jdbc:mysql://192.168.0.19/customersdb
test.driver=com.mysql.jdbc.Driver
test.username=user_db
test.password=*****
test.url=jdbc:mysql://192.168.0.19/customersdb
production.jndi=java:comp/env/jdbc/acme
另外,我有这个网络服务:
@Path("telephone")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class TelephoneResource {
@GET
public Response get() {
try {
Base.open();
LazyList<Telephone> tels= Telephone.findAll();
String telsJson = tels.toJson(true);
Base.close();
return Response.ok().entity(telsJson).build();
} catch (Exception ex) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("{\"error\": \"" + ex.getMessage() + "\"}").build();
}
}
}
但是当我尝试执行该 GET 资源时,我收到以下错误消息:
{
"error": "Could not find configuration in a property file for environment: development. Are you sure you have a database.properties file configured?"
}
我也尝试过其他配置:
- http://javalite.io/database_connection_management#environment-variables-override
- http://javalite.io/database_connection_management#system-properties-override
通过使用maven-surefire-plugin 将它们添加到pom.xml 文件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.13</version>
<configuration>
<systemPropertyVariables>
<activejdbc.url>jdbc:mysql://192.168.0.19/customersdb</activejdbc.url>
<activejdbc.user>user_db</activejdbc.user>
<activejdbc.password>*****</activejdbc.password>
<activejdbc.driver>com.mysql.jdbc.Driver</activejdbc.driver>
</systemPropertyVariables>
<environmentVariables>
<ACTIVEJDBC.URL>jdbc:mysql://192.168.0.19/customersdb</ACTIVEJDBC.URL>
<ACTIVEJDBC.USER>user_db</ACTIVEJDBC.USER>
<ACTIVEJDBC.PASSWORD>*****</ACTIVEJDBC.PASSWORD>
<ACTIVEJDBC.DRIVER>com.mysql.jdbc.Driver</ACTIVEJDBC.DRIVER>
</environmentVariables>
</configuration>
</plugin>
但他们也没有工作。
【问题讨论】:
标签: java maven activejdbc