【问题标题】:How does BlueMix perform Autowiring during deployment?BlueMix 在部署期间如何执行自动装配?
【发布时间】:2015-04-10 19:18:38
【问题描述】:

我下载了 BlueMix Java SQLDB Boilerplate,我正在使用它,查看扩展其他表等。我对将 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?

是否需要满足任何条件或要求才能进行自动装配?

【问题讨论】:

    标签: java boilerplate websphere-liberty ibm-cloud


    【解决方案1】:

    其实很酷。在应用程序部署期间,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)
    

    构建包寻找的是将服务绑定到您的应用程序。如果有 Cloudant 或 Monitoring and Analytics 等绑定服务,它将添加正确的资源。对于 Cloudant,因为它是 JDBC,它会为您创建 JDBC 连接。

    此外,Liberty buildpack 为以下服务类型提供自动配置: SQL 数据库 ClearDB MySQL 数据库 MySQL ElephantSQL PostgreSQL Cloudant™ NoSQL 数据库 MongoLab dashDB 数据缓存 会话缓存 MQ 轻量监控和分析 Auto-Scaling Single Sign On New Relic

    【讨论】:

    • 谢谢 我还在文档中找到了一些附加信息 - ng.bluemix.net/docs/#starters/liberty/… 它定义了自动装配服务的完整列表:Liberty buildpack 为以下服务类型提供自动配置: SQL 数据库 ClearDB MySQL 数据库 MySQL ElephantSQL PostgreSQL Cloudant™ NoSQL 数据库 MongoLab dashDB 数据缓存 会话缓存 MQ 轻量监控和分析 自动扩展 单点登录 New Relic
    • 将其添加到答案中,以便更容易找到
    • Cloudant 不兼容 JDBC。它提供了一个使用 REST API 的 Java 客户端库。答案应该更正,因为认为可以通过 JDBC/JPA 将 cloudant 配置为应用程序服务器的数据源是一种误导。
    猜你喜欢
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-26
    • 2015-08-31
    • 2016-04-25
    • 2014-05-23
    相关资源
    最近更新 更多