BsthServletInitializer.java
1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.ruoyi;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
import java.util.Map;
/**
* web容器中进行部署
*
* @author ruoyi
*/
public class BsthServletInitializer extends SpringBootServletInitializer
{
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application)
{
return application.sources(BsthApplication.class);
}
// 测试方法
public static void main(String[] args) {
RestTemplate restTemplate = new RestTemplate();
String url = "http://1.14.107.94:8100/driver/driver";
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", "Bearer eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImNhOGRhOGJlLWQ0ZjItNDhjMy05ZWU1LWJkMDQzYzY3YzQ0MyJ9.79b8JM31faxhLnIqu6xGtrx1JK019NoN26AwNfPzptYSriHSTABdYp16kzKD538wo2HfXhYoviSqy4qZfoEV5Q");
Map<String, String> requestBody = new HashMap<>();
requestBody.put("jobCode", "asdfasd");
requestBody.put("personnelName", "asdfasdf");
HttpEntity<Map<String, String>> entity = new HttpEntity<>(requestBody, headers);
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, entity, String.class);
String responseBody = response.getBody();
System.out.println(responseBody);
}
}