引子:https://www.ng.bluemix.net/docs/#starters/liberty/index.html#libertyapp
When the application is bound to services, the service binding information is available in the VCAP_SERVICES environment variable. For some services, Liberty automatically generates or updates service binding entries in the server.xml file.
The Liberty buildpack automatically processes service bindings for the following service types:
正文:
SO.不能自动给MYSQL注入jdbc连接信息了.!不过还是要试一下
以相同的方式打包:
C:\IBM\was855nalp\bin>server package simpleServer --archive=hellotest.zip --include=usr
Packaging server simpleServer.
Server simpleServer package complete in C:\IBM\was855nalp\usr\servers\simpleServer\hellotest.zip.
C:\IBM\was855nalp\bin>
这回打的包有1M多,它自动包含了/usr/shared目录
cf login -a https://api.ng.bluemix.net(如果刚才已经登录过,此步不是必须的)
cf bind-service cyperhellotest mysql-cyper(这次先绑定事先建好的mysql服务,可以通过cf services查看已有的服务,如果已经绑定过则可以跳过此步)
cf push cyperhellotest --no-manifest --no-start -p C:\IBM\was855nalp\usr\servers\simpleServer\hellotest.zip(再次上传bluemix足够聪明,usr/shared/resources中的mysql jar这次被无视了)
cf start cyperhellotest
cf logs cyperhellotest
访问url, 只打印出了页面上的静态内容,没有打出DB中的记录
从日志中看出,,失败了!
从bluemix portal中找到VCAP信息,修改server.xml如下
<server description="new server"> <!-- Enable features --> <featureManager> <feature>servlet-3.0</feature> <feature>jdbc-4.0</feature> </featureManager> <dataSource id="blogDS" jndiName="jdbc/blogDS" connectionManagerRef="mysqlPool" jdbcDriverRef="mysqlDriver"> <properties databaseName="dcd5be7bc69d1442d94a89993553042a3" serverName="50.23.230.134" portNumber="3307" user="uuQI5xxxxxx" password="pbJsoOcnYeCjd" /> </dataSource> <connectionManager id="mysqlPool" maxPoolSize="10" /> <jdbcDriver id="mysqlDriver" libraryRef="mysqlLib" /> <library id="mysqlLib" filesetRef="mysqlFileset" /> <fileset id="mysqlFileset" dir="${shared.resource.dir}/mysql" includes="*.jar" /> <webApplication name="helloworld" location="helloworld.war" /> <httpEndpoint id="defaultHttpEndpoint" host="localhost" httpPort="9080" httpsPort="9443" /> </server>重新打包部署.
create table if not exists cities
0624更新配置如下:
<dataSource id="blogDS" jndiName="jdbc/blogDS" connectionManagerRef="mysqlPool" jdbcDriverRef="mysqlDriver"> <properties databaseName="${cloud.services.mysql-cyper.connection.name}" serverName="${cloud.services.mysql-cyper.connection.host}" portNumber="${cloud.services.mysql-cyper.connection.port}" user="${cloud.services.mysql-cyper.connection.user}" password="${cloud.services.mysql-cyper.connection.password}" /> </dataSource>