SPRINGCLOUD14---Zuul

Source: Internet
Author: User

 PackageCom.itmuch.cloud.study;Importorg.springframework.boot.SpringApplication;Importorg.springframework.boot.autoconfigure.SpringBootApplication;Importorg.springframework.cloud.netflix.eureka.EnableEurekaClient, @SpringBootApplication @enableeurekaclient Public classfileuploadapplication { Public Static voidMain (string[] args) {Springapplication.run (fileuploadapplication.class, args); }}
 PackageCom.itmuch.cloud.study.controller;ImportJava.io.File;Importjava.io.IOException;ImportOrg.springframework.stereotype.Controller;Importorg.springframework.util.FileCopyUtils;Importorg.springframework.web.bind.annotation.RequestMapping;ImportOrg.springframework.web.bind.annotation.RequestMethod;ImportOrg.springframework.web.bind.annotation.RequestParam;ImportOrg.springframework.web.bind.annotation.ResponseBody;Importorg.springframework.web.multipart.MultipartFile; @Controller Public classFileuploadcontroller {/**Test with interface:http://localhost: 8050/index.html use cmd command: curl-f "[email protected] File Full name" Localhost:8050/upload@returnthe absolute path of the file on the server*/    //Start the Zuul (Port 8040) via http://localhost:8040/microservice-file-upload/upload Access//also available via http://Localhost:8040/zuul/microservice-file-upload/upload//Zuul upload small file without/zuul prefix, large file plus/zuul bypass spring. /*Zuul upload Large files to the configuration file in the Zuul Project timeout: #经过zuul的请求都会通过hysitrcs包裹, so Zuul will have the circuit breaker function, Configure the Hysitrcs time-out period hystrix.command.default.execution.isolation.thread.timeoutinmilliseconds:60000# Zuul also uses the Ribbon to do load balancing, to the device Ribbon timeout time ribbon:connecttimeout:3000 readtimeout:60000*/@RequestMapping (Value= "/upload", method =requestmethod.post) Public@ResponseBody String handlefileupload (@RequestParam (value = "File", required =true) multipartfile file)throwsIOException {byte[] bytes =file.getbytes (); File Filetosave=NewFile (File.getoriginalfilename ());    Filecopyutils.copy (bytes, filetosave); returnFiletosave.getabsolutepath (); }}
Server:   8050#加入到eurekaeureka:  client:    serviceurl:      defaultzone:http://User:[email protected]:8761/eureka/  instance:    prefertrueSpring:  application:    name:microservice-file-upload  http:    multipart:      max-file-SIZE:2000MB      # max file size, default 1M      max-request-size:2500mb   # max request size, default 10M
<?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>com.itmuch.cloud</groupId> <artifactid>microservice-file-upload </artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <!-- Introducing Spring Boot dependencies--<parent> <groupId>org.springframework.boot</groupId> &LT;ARTIFACTID&GT;SP Ring-boot-starter-parent</artifactid> <version>1.4.2.RELEASE</version> </parent> < Properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version >1.8</java.version> </properties> <dependencies> <dependency> <groupid>org.spri Ngframework.boot</groupid> <artifactId>spring-boot-starter-web</artifactId> </dependency > <dependency> <groupid>org.springframework.cloud</groupid> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency> <d Ependency> <groupId>org.springframework.boot</groupId> &LT;ARTIFACTID&GT;SPRING-BOOT-STARTER-ACTU Ator</artifactid> </dependency> </dependencies> <!--the introduction of Spring Cloud dependency--<dependencyman agement> <dependencies> <dependency> <groupid>org.springframework.cloud</groupid&gt        ; <artifactId>spring-cloud-dependencies</artifactId> <version>Camden.SR2</version> &lt ;type>pom</type> <scope>Import</scope> </dependency> </dependencies> </dependencyManagement> <!--add Spring-boot Mav En plug-in <build> <plugins> <plugin> <groupid>org.springframework.boot</group id> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> < /build></project>

SPRINGCLOUD14---Zuul

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.