創建文件管理微服務service_file,該工程主要用於實現文件上傳以及文件刪除等功能。
(1)修改pom.xml,引入依賴
<?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">
<parent>
<artifactId>service-file</artifactId>
<groupId>com.gzy</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>service_file</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>net.oschina.zcx7878</groupId>
<artifactId>fastdfs-client-java</artifactId>
<version>1.27.0.0</version>
</dependency>
<dependency>
<groupId>com.changgou</groupId>
<artifactId>changgou_common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
(2)在resources文件夾下創建fasfDFS的配置文件fdfs_client.conf
connect_timeout = 60
network_timeout = 60
charset = UTF-8
http.tracker_http_port = 8080
tracker_server = 192.168.200.128:22122
connect_timeout:連接超時時間,單位爲秒。
network_timeout:通信超時時間,單位爲秒。發送或接收數據時。假設在超時時間後還不能發送或接收數據,則本次網絡通信失敗
charset: 字符集
http.tracker_http_port :.tracker的http端口
tracker_server: tracker服務器IP和端口設置
(3)在resources文件夾下創建application.yml
spring:
servlet:
multipart:
max-file-size: 10MB #單個文件大小
max-request-size: 10MB #設置總上傳文件大小
application:
name: file #微服務的應用名稱
server:
port: 9007
eureka:
client:
service-url:
defaultZone: http://127.0.0.1:6868/eureka
instance:
prefer-ip-address: true
feign:
hystrix:
enabled: true
max-file-size是單個文件大小,max-request-size是設置總上傳的數據大小
(4)啓動類,創建啓動類FileApplication
@SpringBootApplication
@EnableEurekaClient
public class FileApplication {
public static void main(String[] args) {
SpringApplication.run(FileApplication.class);
}
}