Home > Back-end >  About Fegin MultipartFile uploading files
About Fegin MultipartFile uploading files

Time:10-01


Now more and more distributed application, through feign to transmit data, but will encounter problems when uploading files, because springcolud feign itself does not support to upload files,
So the need for additional imports to close the jar first,




First , because the most detailed, so each comment as much as possible, don't too OUT, the couple are human, also for them to consider
1
1.1 create the parent project
Create the parent distributed project: the project name Dandy_parent remember & lt; Packaging> Pom


1.2 add springboot and springcloud dependence



2 under Dandy_parent project create Eureka project Dandy_parent_Eureka
2.1 APP where package for the dandy. Eureka


2.2 related dependence:


2.3 application. Yml:

# # # had service port
Server:
Port: 8200

# # single registry does not need the cluster server name
Spring:
Application:
Name: Eureka

# # # service registry IP
Eureka:
Instance:
The hostname: 127.0.0.1

# # it is registered to someone else's IP address is not provided in the registration address!!!!!!
# # the IP address is their own, so to register themselves, just address haven't determine whether or not registered, because here are control whether registered in eureka
Client:
# serviceUrl: equivalent to the service - url:
ServiceUrl:
# http://$registered name {service} : ${service port}/eureka, use more than one, separate,
# is http://$registered name {service} : ${service port}/had been/, http://$registered name {service} : ${service port}/had been/
DefaultZone: http://${eureka. The instance. The hostname} : 8200/had been/

# # # cluster to register yourself for others to use, so when you are single registry if true, is started when he will put himself registered IP, but haven't start to finish, how can I register to oneself, so complains
# # # to register the current service, because is the control center so there is no need to register yourself
The register - with - eureka: false
# # # for it is the control center so there is no need to self-check
The fetch - registry: false

3 in Dandy_parent project created under the service Provider Provider project name: Dandy_parent_Provider
3.1 app where package for the dandy. The provider

3.2 related dependence:

3.3 application. Yml:
Server:
Port: 8082
Spring:
Application:
Name: the Provider
Eureka:
Client:
# service - url=serviceUrl these two are the same as
Service - url:
DefaultZone: http://localhost:8200/eureka
# # # to register their services to the eureka
The register - with - eureka: true
# # # do you need to obtain the registration information from eureka
The fetch - registry: true
# # define in Eurka status display IP address on the web,
Instance:
-- - IP address: true
The instance - id: ${spring. Application. The name} : ${server port}

4 under Dandy_parent project create Feign project name: Dandy_parent_api
4.1 fegin interface package for the dandy. API

4.2
@ Configuration
Public class FeignMultipartSupportConfig {

@ Configuration
Public class FeignMultipartSupportConfig {

The @autowired
Private ObjectFactory MessageConverters.
@ Bean
@ Primary
@ the Scope (" prototype ")
Public Encoder multipartFormEncoder () {
//here to prove Fegin scan can scan to @ Configuration
System. The out. Println ("============@ Configuration==========");
Return new SpringFormEncoder (new SpringEncoder (messageConverters));
}

@ Bean
Public feign. Logger. Level multipartLoggerLevel () {
Return feign. Logger. Level. FULL;
}
}

@ Bean
Public feign. Logger. Level multipartLoggerLevel () {
Return feign. Logger. Level. FULL;
}
}

4.3 related dependence:


5 to create Consumer Consumer projects under Dandy_parent project name: Dandy_parent_Consumer
5.1 Consumer Consumer app the package for the dandy. Consumer

5.2 related dependence:

5.3 application. Yml:
Server:
Port: 8083
Spring:
Application:
Name: Consumer

Eureka:
Client:
Service - url:
DefaultZone: http://localhost:8200/eureka
# # # to register their services to the eureka
The register - with - eureka: true
# # # do you need to obtain the registration information from eureka
The fetch - registry: true
Instance:
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related