version接口

来源:互联网 发布:中科院外籍院士知乎 编辑:程序博客网 时间:2024/04/28 18:44

发包时候一般需要验证是否正确版本

通过脚本在classes目录下生成一个version.txt文件

并在程序中提供version接口

import java.io.IOException;import java.util.List;import org.apache.commons.io.IOUtils;import org.springframework.core.io.ClassPathResource;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.ResponseBody;import org.springframework.web.bind.annotation.RestController;import com.arcsoft.web.openapi.common.basic.BaseController;@RestController@RequestMapping("/rest/service/version")public class VersionController extends BaseController{@RequestMapping(value = "/versionInfo", method = RequestMethod.GET)@ResponseBodypublic Object versionInfo() throws Exception{ClassPathResource res = new ClassPathResource("version.txt");String ret = "unknown, version.txt does not exist!!!";if(res.exists()){List<String> retList = null;try{retList = IOUtils.readLines(res.getInputStream());ret = retList.get(0);}catch(IOException e){e.printStackTrace();}}return ret;}}

0 0
原创粉丝点击