BsthServletInitializer.java 1.64 KB
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);
    }
}