Commit 9fec60aa authored by wangrican's avatar wangrican

feat:增加文件上传、删除服务

parent 7e7d6533
......@@ -14,4 +14,14 @@ public class CommonConstant {
int STATE_START = 1;
int STATE_STOP = 0;
}
/**
* 状态 1.阿里云上传 2.fastdfs
*/
public interface FileType {
int OSS_UPLOAD = 1;
int FASTDFS_UPLOAD = 2;
}
}
HELP.md
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**
!**/src/test/**
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
plugins {
id 'org.springframework.boot' version '2.2.7.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
id 'war'
}
group = 'com.ssy'
version = '2.0.0'
sourceCompatibility = '1.8'
repositories {
maven {
url 'http://10.0.0.21:8081/repository/maven-public/'
}
maven {
url 'https://maven.aliyun.com/repository/public'
}
mavenCentral()
}
ext {
set('springCloudVersion', "Hoxton.SR4")
}
dependencies {
implementation project(':common')
compile group: 'com.github.tobato', name: 'fastdfs-client', version: '1.27.2'
compile group: 'com.aliyun.oss', name: 'aliyun-sdk-oss', version: '3.8.0'
compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.7.0'
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.7.0'
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-openfeign', version: '2.2.2.RELEASE'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.cloud:spring-cloud-starter-consul-discovery'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
test {
useJUnitPlatform()
}
#Mon Jun 15 13:48:11 CST 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
#!/usr/bin/env sh
#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=`expr $i + 1`
done
case $i in
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=`save "$@"`
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
exec "$JAVACMD" "$@"
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
rootProject.name = 'file-srevice'
include 'common'
project(':common').projectDir = "../common" as File
\ No newline at end of file
package com.ssy;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableSwagger2
@SpringBootApplication
public class FileSreviceApplication {
public static void main(String[] args) {
SpringApplication.run(FileSreviceApplication.class, args);
}
}
package com.ssy.file.srevice.config;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
@Component
@Configuration
public class ConstantConfig {
@Value("${aliyun.file.endpoint}")
private String endpoint;
@Value("${aliyun.file.accessKeyId}")
private String accessKeyId;
@Value("${aliyun.file.accessKeySecret}")
private String accessKeySecret;
@Value("${aliyun.file.folder}")
private String folder;
@Value("${aliyun.file.bucketName}")
private String bucketName;
@Value("${aliyun.file.webUrl}")
private String webUrl;
@Bean
//@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE )
public OSS getOSSClient(){
return new OSSClientBuilder().build(
endpoint,
accessKeyId,
accessKeySecret);
}
public String getEndpoint() {
return endpoint;
}
public void setEndpoint(String endpoint) {
this.endpoint = endpoint;
}
public String getAccessKeyId() {
return accessKeyId;
}
public void setAccessKeyId(String accessKeyId) {
this.accessKeyId = accessKeyId;
}
public String getAccessKeySecret() {
return accessKeySecret;
}
public void setAccessKeySecret(String accessKeySecret) {
this.accessKeySecret = accessKeySecret;
}
public String getFolder() {
return folder;
}
public void setFolder(String folder) {
this.folder = folder;
}
public String getBucketName() {
return bucketName;
}
public void setBucketName(String bucketName) {
this.bucketName = bucketName;
}
public String getWebUrl() {
return webUrl;
}
public void setWebUrl(String webUrl) {
this.webUrl = webUrl;
}
}
package com.ssy.file.srevice.config;
import com.github.tobato.fastdfs.FdfsClientConfig;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableMBeanExport;
import org.springframework.context.annotation.Import;
import org.springframework.jmx.support.RegistrationPolicy;
/**
* 文件上传配置类
* @Author: wrc
* @Date: 2020/6/15
*/
@Configuration
@Import(FdfsClientConfig.class) // 导入FastDFS-Client组件
@EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING) // 解决jmx重复注册bean的问题
public class FdfsConfiguration {
}
\ No newline at end of file
package com.ssy.file.srevice.controller;
import com.ssy.common.response.Wrapper;
import com.ssy.file.srevice.service.FileUploadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
@Api(tags = "文件管理")
@RestController
@RequestMapping("/file")
public class UploadController {
@Autowired
FileUploadService fileUploadService;
/**
* 上传文件没有限制文件类型
* fileType 文件上传类型:1.阿里云oss 2.fastdfs
* @Author: wrc
* @Date: 2020/5/29
*/
@ApiOperation(value = " 文件上传")
@PostMapping("/upload")
public Wrapper upload(@RequestParam("file") MultipartFile file, Integer fileType) {
return fileUploadService.upload(file, fileType);
}
/**
* 删除文件-根据文件访问url删除
* fileType 文件上传类型:1.阿里云oss 2.fastdfs
* @Author: wrc
* @Date: 2020/5/29
*/
@ApiOperation(value = " 删除文件")
@PostMapping("/delete")
public Wrapper delete(@RequestParam(value = "fileUrl") String fileUrl, Integer fileType) {
return fileUploadService.delete(fileUrl,fileType);
}
}
package com.ssy.file.srevice.service;
import com.ssy.common.response.Wrapper;
import org.springframework.web.multipart.MultipartFile;
public interface FileUploadService {
/**
* 文件上传
* @Author: wrc
* @Date: 2020/5/29
*/
Wrapper upload(MultipartFile request, Integer fileType);
/**
* 文件删除
* @Author: wrc
* @Date: 2020/5/29
*/
Wrapper delete(String fileUrl, Integer fileType);
}
package com.ssy.file.srevice.service.impl;
import com.ssy.common.constant.CommonConstant;
import com.ssy.common.response.Wrapper;
import com.ssy.file.srevice.service.FileUploadService;
import com.ssy.file.srevice.utils.AliyunOSSUtil;
import com.ssy.file.srevice.utils.FastDFSClientUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
@Service
public class FileUploadServiceImpl implements FileUploadService {
Logger log= LoggerFactory.getLogger(FileUploadServiceImpl.class);
@Autowired
AliyunOSSUtil aliyunOSSUtil;
@Autowired
FastDFSClientUtil fastDFSClientUtil;
/**
* 文件上传
* @param request 文件
* @param fileType 上传文件方式:1.阿里云 2.fastdfs
* @Author: wrc
* @Date: 2020/5/29
*/
@Override
public Wrapper upload(MultipartFile request, Integer fileType) {
String fileUrl = null;
if(null==request){
Wrapper.failService("无效文件");
}
if(CommonConstant.FileType.OSS_UPLOAD==fileType){
try {
fileUrl = aliyunOSSUtil.upload(request.getInputStream(),request.getOriginalFilename());
} catch (Exception e) {
log.error("文件上传异常",e);
}
}else{
fileUrl = fastDFSClientUtil.uploadFile(request);
}
return Wrapper.success(fileUrl);
}
/**
* 文件删除
*
* @param fileUrl
* @Author: wrc
* @Date: 2020/5/29
*/
@Override
public Wrapper delete(String fileUrl, Integer fileType) {
if(CommonConstant.FileType.OSS_UPLOAD==fileType){
aliyunOSSUtil.deleteFile(fileUrl);
}else{
fastDFSClientUtil.delFile(fileUrl);
}
return Wrapper.success();
}
}
package com.ssy.file.srevice.utils;
import com.aliyun.oss.OSS;
import com.aliyun.oss.model.ListObjectsRequest;
import com.aliyun.oss.model.OSSObjectSummary;
import com.aliyun.oss.model.ObjectListing;
import com.aliyun.oss.model.PutObjectResult;
import com.ssy.file.srevice.config.ConstantConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.InputStream;
import java.util.List;
import java.util.UUID;
@Component
public class AliyunOSSUtil {
private static final Logger logger = LoggerFactory.getLogger(AliyunOSSUtil.class);
private static final String HTTP = "https://";
@Autowired
private ConstantConfig constantConfig;
@Autowired
OSS client;
/**
* 上传
* @param inputStream
* @param fileName
* @return
*/
public String upload(InputStream inputStream, String fileName) {
String url = null;
try {
//切割文件名字
String suffix = fileName.split("\\.")[1];
fileName= UUID.randomUUID().toString().replace("-","")+System.currentTimeMillis()+".".concat(suffix);
PutObjectResult putObjectResult = client.putObject(constantConfig.getBucketName(), fileName, inputStream);
if (null != putObjectResult) {
StringBuilder urlBuffer = new StringBuilder();
urlBuffer.append(HTTP).append(constantConfig.getBucketName()).append(".").append(constantConfig.getWebUrl()).append("/").append(fileName);
url = urlBuffer.toString();
}
} catch (Exception e) {
e.printStackTrace();
logger.error("文件上传异常",e);
}
return url;
}
/**
* 根据文件url删除文件
* @Author: wrc
* @Date: 2020/5/29
*/
public void deleteFile(String filePath){
String[] split = filePath.split("\\/");
filePath = split[split.length-1];
client.deleteObject(constantConfig.getBucketName(), filePath);
}
/**
* 查看文件列表 包含指定前缀(prefix)的文件
* maxKeys 文件查询数量
* prefix 包含prefix前缀的文件
*nextMarker 下一个标记
* 文档链接 https://help.aliyun.com/document_detail/84841.html?spm=a2c4g.11186623.2.13.3ad5b5ddqxWWRu#concept-84841-zh
* @Author: wrc
* @Date: 2020/5/29
*/
public List<OSSObjectSummary> list(int maxKeys, String prefix, String nextMarker) {
ObjectListing objectListing;
List<OSSObjectSummary> sums=null;
do {
objectListing = client.listObjects(new ListObjectsRequest(constantConfig.getBucketName()).
withPrefix(prefix).withMarker(nextMarker).withMaxKeys(maxKeys));
sums = objectListing.getObjectSummaries();
nextMarker = objectListing.getNextMarker();
} while (objectListing.isTruncated());
return sums;
}
}
package com.ssy.file.srevice.utils;
import com.github.tobato.fastdfs.domain.fdfs.StorePath;
import com.github.tobato.fastdfs.domain.fdfs.ThumbImageConfig;
import com.github.tobato.fastdfs.domain.proto.storage.DownloadCallback;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import org.apache.commons.io.FilenameUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.io.InputStream;
@Component
public class FastDFSClientUtil {
private Logger log= LoggerFactory.getLogger(FastDFSClientUtil.class);
@Value("${fdfs.reqHost}")
private String reqHost;
@Value("${fdfs.reqPort}")
private String reqPort;
@Autowired
private FastFileStorageClient storageClient;
@Autowired
private ThumbImageConfig thumbImageConfig; //创建缩略图 , 缩略图访问有问题,暂未解决
public String uploadFile(MultipartFile file) {
StorePath storePath = null;
try {
storePath = storageClient.uploadFile(file.getInputStream(),file.getSize(), FilenameUtils.getExtension(file.getOriginalFilename()),null);
} catch (IOException e) {
log.error("文件上传异常",e);
}
return getResAccessUrl(storePath);
}
public void delFile(String filePath) {
storageClient.deleteFile(filePath);
}
public InputStream download(String groupName, String path ) {
InputStream ins = storageClient.downloadFile(groupName, path, new DownloadCallback<InputStream>(){
@Override
public InputStream recv(InputStream ins) throws IOException {
// 将此ins返回给上面的ins
return ins;
}}) ;
return ins ;
}
/**
* 封装文件完整URL地址
* @param storePath
* @return
*/
private String getResAccessUrl(StorePath storePath) {
String fileUrl = "http://" + reqHost + ":" + reqPort + "/" + storePath.getFullPath();
return fileUrl;
}
}
\ No newline at end of file
spring:
cloud:
consul:
host: 10.0.0.24
port: 8500
discovery:
prefer-ip-address: true
# 禁止使用Ribbon,否则启动的时候会报Warning信息
loadbalancer:
ribbon:
enabled: false
# 链路追踪Zipkin配置
zipkin:
base-url: http://10.0.0.24:9411
redis:
host: 10.0.0.16
port: 6379
#redis默认有16个数据库,指定要使用的数据库,0-15,第一个是0
database: 0
#连接到redis服务器的超时时间,ms
timeout: 3000
# 监控配置。如果不配置则无法访问/actuator/health,info,beans等接口,Consul注册中心会报错(但仍可注册)
management:
endpoints:
web:
base-path: /actuator
exposure:
include: "*"
fdfs:
soTimeout: 1500
connectTimeout: 600
reqHost: 10.0.0.28
reqPort: 88
thumbImage:
width: 150
height: 150
trackerList:
- 10.0.0.28:22122
aliyun:
file:
endpoint: http://oss-cn-shenzhen.aliyuncs.com
accessKeyId: LTAI4FogcK9Ftw81JNDTUgXF
accessKeySecret: 43TCFNGzSlAvXv4keRZ8CY9ztL1RkI
bucketName: shushangyun01
folder : 11
webUrl: oss-cn-shenzhen.aliyuncs.com
spring:
cloud:
consul:
host: 10.0.0.25
port: 8500
discovery:
prefer-ip-address: true
# 禁止使用Ribbon,否则启动的时候会报Warning信息
loadbalancer:
ribbon:
enabled: false
redis:
host: 10.0.0.16
port: 6379
#redis默认有16个数据库,指定要使用的数据库,0-15,第一个是0
database: 0
#连接到redis服务器的超时时间,ms
timeout: 3000
# 监控配置。如果不配置则无法访问/actuator/health,info,beans等接口,Consul注册中心会报错(但仍可注册)
management:
endpoints:
web:
base-path: /actuator
exposure:
include: "*"
fdfs:
soTimeout: 1500
connectTimeout: 600
reqHost: 10.0.0.28
reqPort: 88
thumbImage:
width: 150
height: 150
trackerList:
- 10.0.0.28:22122
aliyun:
file:
endpoint: http://oss-cn-shenzhen.aliyuncs.com
accessKeyId: LTAI4FogcK9Ftw81JNDTUgXF
accessKeySecret: 43TCFNGzSlAvXv4keRZ8CY9ztL1RkI
bucketName: shushangyun01
folder : 11
webUrl: oss-cn-shenzhen.aliyuncs.com
\ No newline at end of file
spring:
profiles:
active: dev
application:
name: file-srevice
main:
allow-bean-definition-overriding: true
server:
port: 7010
tomcat:
uri-encoding: UTF-8
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<springProperty scope="context" name="APPLICATION_PORT" source="server.port"/>
<springProperty scope="context" name="APPLICATION_IP_ADDRESS" source="spring.cloud.client.ipAddress"/>
<springProperty scope="context" name="APPLICATION_NAME" source="spring.application.name"/>
<!-- 开发环境 -->
<springProfile name="dev">
<property name="PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [${APPLICATION_NAME},%X{X-B3-TraceId},%X{X-B3-SpanId},%X{X-Span-Export}] %thread %logger %msg%n"/>
<property name="FILE_PATH" value="/usr/local/logs/${APPLICATION_NAME}/${APPLICATION_PORT}/"/>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${FILE_PATH}/${APPLICATION_NAME}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${FILE_PATH}/${APPLICATION_NAME}-%d{yyyy-MM-dd}-%i.log.gz</fileNamePattern>
<maxFileSize>10MB</maxFileSize>
</rollingPolicy>
<encoder>
<pattern>${PATTERN}</pattern>
<charset>utf-8</charset>
</encoder>
</appender>
<appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="FILE" />
</appender>
<!-- 不打印NACOS心跳日志 -->
<logger name="com.alibaba.nacos" level="WARN"/>
<root level="INFO">
<appender-ref ref="ASYNC"/>
</root>
</springProfile>
<!-- 测试环境 -->
<springProfile name="test">
<property name="PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [${APPLICATION_NAME},%X{X-B3-TraceId},%X{X-B3-SpanId},%X{X-Span-Export}] %thread %logger %msg%n"/>
<property name="FILE_PATH" value="/usr/local/logs/${APPLICATION_NAME}/${APPLICATION_PORT}"/>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${FILE_PATH}/${APPLICATION_NAME}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${FILE_PATH}/${APPLICATION_NAME}-%d{yyyy-MM-dd}-%i.log.gz</fileNamePattern>
<maxFileSize>10MB</maxFileSize>
</rollingPolicy>
<encoder>
<pattern>${PATTERN}</pattern>
<charset>utf-8</charset>
</encoder>
</appender>
<appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="FILE" />
</appender>
<!-- 不打印NACOS心跳日志 -->
<logger name="com.alibaba.nacos" level="WARN"/>
<root level="INFO">
<appender-ref ref="ASYNC"/>
</root>
</springProfile>
<!-- 测试环境 -->
<springProfile name="pre">
<property name="PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [${APPLICATION_NAME},%X{X-B3-TraceId},%X{X-B3-SpanId},%X{X-Span-Export}] %thread %logger %msg%n"/>
<property name="FILE_PATH" value="/usr/local/logs/${APPLICATION_NAME}/${APPLICATION_PORT}"/>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${FILE_PATH}/${APPLICATION_NAME}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${FILE_PATH}/${APPLICATION_NAME}-%d{yyyy-MM-dd}-%i.log.gz</fileNamePattern>
<maxFileSize>10MB</maxFileSize>
</rollingPolicy>
<encoder>
<pattern>${PATTERN}</pattern>
<charset>utf-8</charset>
</encoder>
</appender>
<appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="FILE" />
</appender>
<!-- 不打印NACOS心跳日志 -->
<logger name="com.alibaba.nacos" level="WARN"/>
<root level="INFO">
<appender-ref ref="ASYNC"/>
</root>
</springProfile>
<!-- 生产环境 -->
<springProfile name="prod">
<property name="PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [${APPLICATION_NAME},%X{X-B3-TraceId},%X{X-B3-SpanId},%X{X-Span-Export}] %thread %logger %msg%n"/>
<property name="FILE_PATH" value="/usr/local/logs/${APPLICATION_NAME}/${APPLICATION_PORT}"/>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${FILE_PATH}/${APPLICATION_NAME}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${FILE_PATH}/${APPLICATION_NAME}-%d{yyyy-MM-dd}-%i.log.gz</fileNamePattern>
<maxFileSize>10MB</maxFileSize>
</rollingPolicy>
<encoder>
<pattern>${PATTERN}</pattern>
<charset>utf-8</charset>
</encoder>
</appender>
<appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="FILE" />
</appender>
<!-- 不打印NACOS心跳日志 -->
<logger name="com.alibaba.nacos" level="WARN"/>
<root level="INFO">
<appender-ref ref="ASYNC"/>
</root>
</springProfile>
</configuration>
\ No newline at end of file
package com.ssy.file.srevice;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class FileSreviceApplicationTests {
@Test
void contextLoads() {
}
}
......@@ -7,6 +7,7 @@ include 'multi-member-service:platform-member-service'
include 'system-service'
include 'workflow-service'
include 'multi-member-service:merchant-member-service:merchant-member-service-api'
include 'file-srevice'
//findProject(':multi-member-service:merchant-member-service:merchant-member-service-api')?.name = 'merchant-member-service-api'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment