基于CSE开发新的微服务
这里通过开发一个名为helloworldprovider微服务,介绍微服务开发的流程。
工具/原料
已获取AK/SK。
已获取并安装JDK1.8。
已获取并安装Maven,要求3.3.0以上版本。
已获取并安装Eclipse,要求4.5.0以上版本。
创建服务
1、配置maven setting文件以获取SDK依赖。1、profiles中增加如下配置。<profile> <id>稆糨孝汶;nexusProfile</id> <repositories> <repository> <id>cse1</id> <url>http://maven.huaweicse.com/nexus/content/groups/public/</url> </repository> </repositories></profile>2、新增activeProfiles配置。<activeProfiles> <activeProfile>nexusProfile</activeProfile></activeProfiles>
2、在https://servicestage.huaweicloud.com/ser箪滹埘麽vicestage/?project=cn-north-1#/cse/home的“应用开发 > 微服务开发 > 本地工程” 页面,创建并下载一个helloworldprovider工程。
3、解压,并在Eclipse导入Maven工程。
修改代码
1、修改src/main/resources目录下的microservice.ya ml文件,用于存放配置信息。此处按照使用线上服务中心的方式配置。
2、修改代码,作为后期验证的输出。
运行工程
1、在Eclipse中选中目标工程运行“Run as > Maven i nstall”。由于网络原因,首次在apache中央仓库下载某 些依赖包可能失败,因此首次导入时,可多次 执行maven install下载全量依赖包。
2、在helloworldproviderApplication.java上右键执行“Run as > Java Application”。
3、进入界面“应用开发 > 微服务管理 > 服务目录”下就可以看到helloworldprovider微服务。
4、使用浏览器访问http://127.0.0.1:8087/{Service Name}/helloworld?name=“Tom惯墀眚篪”,窗口中打印"Welcome, \"Tom\"",表明服务已在正常运行。