我下载了BlueMix Java SQLDB Boilerplate,我正在玩它,正在寻找扩展其他表等等。我对发生的'autowiring'有点困惑,它将BlueMix中的数据库服务链接到应用程序部署/运行。
在样板文件中,persistence.xml中有一些配置说:
<persistence-unit name="openjpa-todo">
<!-- The cloudAutowiring-1.0 Liberty feature will resolve this to whatever
the database service name is -->
<!-- When running locally without this feature, create a datasource with
the JNDI name "jdbc/mydbdatasource" in server.xml -->
<!-- If using MySQL locally then use the "url" property and append "?relaxAutoCommit=true", for example:
<dataSource id='mysql-datasource' jdbcDriverRef='mysql-driver' jndiName='jdbc/mydbdatasource'>
<properties user='root' password='password' url="jdbc:mysql://localhost:3306/db?relaxAutoCommit=true"/>
</dataSource> -->
<jta-data-source>java:comp/env/jdbc/mydbdatasource</jta-data-source>
<class>example.jpa.TODO</class>
<properties>
<!-- allow table definitions/creation on-the-fly jpa-2.0 feature -->
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)" />
<!-- allow table definitions/creation on-the-fly jpa-2.1 feature -->
<property name="eclipselink.ddl-generation" value="create-tables"/>
</properties>
</persistence-unit>
BlueMix / Liberty如何从已部署的服务映射到jta-data-source / persistence-unit?
自动装配是否需要满足任何条件或要求?
答案 0 :(得分:4)
实际上非常酷。在部署应用程序期间,buildpack允许您执行一些额外的逻辑。 Liberty buildpack中有一些逻辑可以自动连接几个服务。监控和分析,记录,仅举几例。节点buildpack也是这样做的。
我已经捕获了下面的一些自动装配。
2015-04-10T15:24:51.98-0400 [STG] OUT -----> Liberty Buildpack Version: v1.15-20150402-1422
2015-04-10T15:24:51.98-0400 [STG] OUT -----> Retrieving IBM 7.1.2_sr2fp11ifx-20150312 JRE (ibm-java-jre-7.1-2.11-pxa6470_27sr2fp11ifx-20150312_01-sfj.tgz) ... (0.0s)
2015-04-10T15:24:52.82-0400 [STG] OUT Expanding JRE to .java ... (0.8s)
2015-04-10T15:24:52.82-0400 [STG] OUT -----> Retrieving App Management Agent 2015.03.09_101422 (com.ibm.ws.cloudoe.app-mgmt-proxy-agent.zip) ... (0.0s)
2015-04-10T15:24:52.92-0400 [STG] OUT Expanding App Management to .app-management (0.0s)
2015-04-10T15:24:52.92-0400 [STG] OUT -----> Retrieving com.ibm.ws.liberty-2015.3.0.0-201504021422.tar.gz ... (0.0s)
2015-04-10T15:24:53.74-0400 [STG] OUT Installing archive ... (0.8s)
2015-04-10T15:24:53.76-0400 [STG] OUT -----> Retrieving com.ibm.ws.liberty.ext-2015.3.0.0-201504021422.tar.gz ... (0.0s)
2015-04-10T15:24:54.15-0400 [STG] OUT Installing archive ... (0.3s)
2015-04-10T15:24:54.33-0400 [STG] OUT -----> Retrieving and installing client jar(s) from com.ibm.ws.icap.clientJars.cloudant.zip (0.1s)
2015-04-10T15:24:54.34-0400 [STG] OUT -----> Auto-configuration is creating config for service instance 'Cloudant NoSQL DB-wr' of type 'cloudantNoSQLDB'
2015-04-10T15:24:54.36-0400 [STG] OUT -----> Liberty buildpack is done creating the droplet
2015-04-10T15:24:54.63-0400 [STG] ERR
2015-04-10T15:25:06.80-0400 [STG] OUT -----> Uploading droplet (147M)
buildpacks寻找的是绑定到您应用的服务。如果存在绑定服务(如Cloudant或Monitoring and Analytics),则会添加正确的资源。对于Cloudant,因为它是JDBC,它将为您创建JDBC连接。
此外,Liberty buildpack还为以下服务类型提供自动配置:SQL Database ClearDB MySQL数据库MySQL ElephantSQL PostgreSQL Cloudant™NoSQL数据库MongoLab dashDB数据缓存会话缓存MQ光监控和分析自动扩展单一登录新文件