系列4:部署刚才的hello mysql jdbc到bluemix云

引子: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:

  • Relational DataBase (SQLDB via DB2®)
  • NoSQL DataBase (Mongo)
  • Logging (LogAnalysis)

正文:

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>
重新打包部署.
server package simpleServer --archive=hellotest.zip --include=usr
cf push cyperhellotest --no-manifest -p C:\IBM\was855nalp\usr\servers\simpleServer\hellotest.zip

通过cyperhellotest.ng.bluemix.net/helloworld/HelloServlet
或cyperhellotest.mybluemix.net/helloworld/HelloServlet
访问成功
系列4:部署刚才的hello mysql jdbc到bluemix云


PS:如果因为某些原因报Table cities already exists!, 则在create table前drop table就行了.
drop table if exists cities

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>




你可能感兴趣的:(CF,bluemix)