知乎專欄 | 多維度架構 | | | 微信號 netkiller-ebook | | | QQ群:128659835 請註明“讀者” |
Spring boot 每次升級打包發給運維操作,常常運維操作不當致使升級失敗,開發怎樣確認線上的jar/war包與升級包一致呢?
請看下面的解決方案
所有 RestController將會整合 CommonRestController
package cn.netkiller.api.rest; import org.springframework.http.HttpStatus; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseStatus; public class CommonRestController { @RequestMapping("ping") @ResponseStatus(HttpStatus.OK) public String welcome() { return "PONG"; } @RequestMapping("commit") public String commit() { return "$Id$"; } @RequestMapping("auth") @ResponseStatus(HttpStatus.OK) public String auth(@AuthenticationPrincipal final UserDetails user) { return String.format("%s: %s %s", user.getUsername(), user.getPassword(), user.getAuthorities()); } }
我們創建一個RestController並繼承CommonRestController用來測試
package cn.netkiller.api.rest; @RestController @RequestMapping("/public/version") public class VersionRestController extends CommonRestController { private static final Logger logger = LoggerFactory.getLogger(VersionRestController.class); public VersionRestController() { // TODO Auto-generated constructor stub } @RequestMapping("welcome") @ResponseStatus(HttpStatus.OK) public String welcome() { return "Welcome to RestTemplate version 1.0."; } }