3

シンプルな Spring Cloud モデルを作成しようとしています: Zuul、Eureka、MyService1、MyService2。

MyService1 と Myservice2 は Eureka によって登録されます。

MyService1 が構成されました:

@EnableAutoConfiguration
@ComponentScan
@EnableEurekaClient
@EnableJpaRepositories
@EnableFeignClients
public class ServiceOne {
    public static void main(String[] args){
        SpringApplication.run(ServiceOne.class, args);
    }
}

ファイルを MyService2 にアップロードするための RestTemplate があります。

@Autowired
private RestTemplate restTemplate;

LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
map.put("file", Arrays.asList(new Object[] {new ClassPathResource("testfile.txt")}));
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
HttpEntity<LinkedMultiValueMap<String, Object>> requestEntity = new HttpEntity<>(map, headers);
restTemplate.postForObject("http://service2", requestEntity, String.class);

MyService2 の構成:

@SpringBootApplication
@Configuration
@ComponentScan
@EnableEurekaClient
public class ServiceTwo {
    public static void main(String[] args) {
        SpringApplication.run(ServiceTwo.class, args);
    }
}

そしてRestControllerがあります:

@RestController
@RequestMapping(value = AppRestController.REST_URL)
public class RootController {
@RequestMapping(value = "/context}", method = RequestMethod.POST)
    public ResponseEntity<String> upload (MultipartFile file) {
        ...

    }
}

リクエスト受信者

ルートコントローラー

、 しかし

ファイル == ヌル。

RestTemplateを含む単純SpringBoot アプリケーションを作成しました。

public class TestRestTemplate {
    public static void main(String[] args) {
        LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
        map.put("file", Arrays.asList(new Object[] {new ClassPathResource("testfile.txt")}));
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.MULTIPART_FORM_DATA);
        HttpEntity<LinkedMultiValueMap<String, Object>> requestEntity = new HttpEntity<>(map, headers);
        RestTemplate restTemplate = new RestTemplate();
        //Zuul address
        restTemplate.postForObject("http://localhost:8761/service2", requestEntity, String.class);
    }
}

私は何を間違っていますか?

4

1 に答える 1