我在Bluemix中有一个用户定义的服务(不在Bluemix云上的内部部署数据库),凭据如下所示:
System-Provided:
{
"VCAP_SERVICES": {
"user-provided": [
{
"credentials": {
"dbname": "",
"host": "",
"password": "",
"port": "",
"username": ""
},
"label": "user-provided",
"name": "some-service",
"syslog_drain_url": "",
"tags": []
}
]
}
}
有没有办法以某种方式解析JSON并将其读入这些持久性单元属性?
<properties>
<property name="javax.persistence.jdbc.driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<property name="javax.persistence.jdbc.url" value=''/>
<property name="javax.persistence.jdbc.user" value=""/>
<property name="javax.persistence.jdbc.password" value=""/>
</properties>
答案 0 :(得分:0)
创建EntityManagerFactory
时,您可以传递自定义值来覆盖这样的持久性文件:
HashMap<String,String> props=new HashMap<>();
props.put("javax.persistence.jdbc.url", "yourUserName");
EntityManagerFactory emf=Persistence.createEntityManagerFactory("YourPersistenceUnitPU",props);
要解析JSON,您可以使用google gson lib。