Для настройки и запуска Spring Boot приложений требуется следующее:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<packaging>jar</packaging>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>springboot.topjava.ru</groupId>
<artifactId>SpringBootRestService</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package springboot.topjava.ru;
public class PaymentRequest {
private int userId;
private String itemId;
private double discount;
public String getItemId() {
return itemId;
}
public void setItemId(String itemId) {
this.itemId = itemId;
}
public double getDiscount() {
return discount;
}
public void setDiscount(double discount) {
this.discount = discount;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
}
package springboot.topjava.ru;
public class BaseResponse {
private final String status;
private final Integer code;
public BaseResponse(String status, Integer code) {
this.status = status;
this.code = code;
}
public String getStatus() {
return status;
}
public Integer getCode() {
return code;
}
}
package springboot.topjava.ru;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/payment")
public class PaymentController {
private final String sharedKey = "SHARED_KEY";
private static final String SUCCESS_STATUS = "success";
private static final String ERROR_STATUS = "error";
private static final int CODE_SUCCESS = 100;
private static final int AUTH_FAILURE = 102;
@GetMapping
public BaseResponse showStatus() {
return new BaseResponse(SUCCESS_STATUS, 1);
}
@PostMapping("/pay")
public BaseResponse pay(@RequestParam(value = "key") String key, @RequestBody PaymentRequest request) {
final BaseResponse response;
if (sharedKey.equalsIgnoreCase(key)) {
int userId = request.getUserId();
String itemId = request.getItemId();
double discount = request.getDiscount();
// Process the request
// ....
// Return success response to the client.
response = new BaseResponse(SUCCESS_STATUS, CODE_SUCCESS);
} else {
response = new BaseResponse(ERROR_STATUS, AUTH_FAILURE);
}
return response;
}
}
package springboot.topjava.ru;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
В переводе обновили информацию: