当前位置: 首页 > news >正文

010 OSS文件上传

文章目录

  • 直接上传文件到oss中
    • 上传文件(硬编码)
    • 上传文件(配置文件)
    • 上传文件模块
  • 服务端签名直传
  • 前端
    • 上传组件
      • policy.js
      • singleUpload.vue
    • brand-add-or-update.vue
    • brand.vue
    • index.js
  • 后端
    • cubemall-gateway
      • application.yml
    • cubemall-third-party
      • OssController.java
      • CubemallThirdPartyApplication.java
      • application.yml
      • pom.xml

https://element.eleme.cn/#/zh-CN/component/table
src/utils/index.js

/*** 是否有权限* @param {*} key*/
export function isAuth (key) {//return JSON.parse(sessionStorage.getItem('permissions') || '[]').indexOf(key) !== -1 || falsereturn true
}

直接上传文件到oss中

上传文件(硬编码)

<dependency><groupId>com.aliyun.oss</groupId><artifactId>aliyun-sdk-oss</artifactId><version>3.17.4</version>
</dependency>
package com.xd.cubemall.product;import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest;import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.model.PutObjectRequest;
import com.aliyun.oss.model.PutObjectResult;
import java.io.FileInputStream;
import java.io.InputStream;@SpringBootTest
public class CubemallProductApplicationTests {@Testpublic void test() throws Exception{// Endpoint以华东2(上海)为例,其它Region请按实际情况填写。String endpoint = "https://oss-cn-shanghai.aliyuncs.com";// 从环境变量中获取访问凭证。运行本代码示例之前,请确保已设置环境变量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。//EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();//阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议创建并使用RAM用户进行API访问或日常运维,登录RAM控制台创建RAM用户。String accessKeyId = "";String accessKeySecret = "";// 填写Bucket名称,例如examplebucket。String bucketName = "";// 填写Object完整路径,完整路径中不能包含Bucket名称,例如exampledir/exampleobject.txt。String objectName = "";// 填写本地文件的完整路径,例如D:\\localpath\\examplefile.txt。// 如果未指定本地路径,则默认从示例程序所属项目对应本地路径中上传文件流。String filePath= "";// 创建OSSClient实例。OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);try {InputStream inputStream = new FileInputStream(filePath);// 创建PutObjectRequest对象。PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectName, inputStream);// 创建PutObject请求。PutObjectResult result = ossClient.putObject(putObjectRequest);} catch (OSSException oe) {System.out.println("Caught an OSSException, which means your request made it to OSS, "+ "but was rejected with an error response for some reason.");System.out.println("Error Message:" + oe.getErrorMessage());System.out.println("Error Code:" + oe.getErrorCode());System.out.println("Request ID:" + oe.getRequestId());System.out.println("Host ID:" + oe.getHostId());} catch (ClientException ce) {System.out.println("Caught an ClientException, which means the client encountered "+ "a serious internal problem while trying to communicate with OSS, "+ "such as not being able to access the network.");System.out.println("Error Message:" + ce.getMessage());} finally {if (ossClient != null) {ossClient.shutdown();}}System.out.println("上传成功");}}

上传文件(配置文件)

<dependencies><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alicloud-oss</artifactId></dependency>
</dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-alibaba-dependencies</artifactId><version>2.1.0.RELEASE</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement>
spring:datasource:driver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://localhost:3306/cube_goods?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghaiusername: rootpassword: rootcloud:nacos:discovery:server-addr: 127.0.0.1:8848alicloud:oss:endpoint: oss-cn-shanghai.aliyuncs.comaccess-key: secret-key: application:name: cubemall-product
server:port: 8081
package com.xd.cubemall.product;import com.aliyun.oss.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import com.aliyun.oss.model.PutObjectRequest;
import com.aliyun.oss.model.PutObjectResult;
import org.springframework.test.context.junit4.SpringRunner;import java.io.FileInputStream;
import java.io.InputStream;@RunWith(SpringRunner.class)
@SpringBootTest
public class CubemallProductApplicationTests {@Autowiredprivate OSSClient ossClient;@Testpublic void test() throws Exception{// 填写Bucket名称,例如examplebucket。String bucketName = "";// 填写Object完整路径,完整路径中不能包含Bucket名称,例如exampledir/exampleobject.txt。String objectName = "";// 填写本地文件的完整路径,例如D:\\localpath\\examplefile.txt。// 如果未指定本地路径,则默认从示例程序所属项目对应本地路径中上传文件流。String filePath= "";try {InputStream inputStream = new FileInputStream(filePath);// 创建PutObjectRequest对象。PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectName, inputStream);// 创建PutObject请求。PutObjectResult result = ossClient.putObject(putObjectRequest);} catch (OSSException oe) {System.out.println("Caught an OSSException, which means your request made it to OSS, "+ "but was rejected with an error response for some reason.");System.out.println("Error Message:" + oe.getErrorMessage());System.out.println("Error Code:" + oe.getErrorCode());System.out.println("Request ID:" + oe.getRequestId());System.out.println("Host ID:" + oe.getHostId());} catch (ClientException ce) {System.out.println("Caught an ClientException, which means the client encountered "+ "a serious internal problem while trying to communicate with OSS, "+ "such as not being able to access the network.");System.out.println("Error Message:" + ce.getMessage());} finally {if (ossClient != null) {ossClient.shutdown();}}System.out.println("上传成功");}}

上传文件模块

Added dependencies
Spring Web
Open Feign

spring:cloud:nacos:discovery:server-addr: 127.0.0.1:8848alicloud:oss:endpoint: oss-cn-shanghai.aliyuncs.comaccess-key: secret-key: application:name: cubemall-third-party
server:port: 30000
        <dependency><groupId>com.xd.cubemall</groupId><artifactId>cubemall-common</artifactId><version>0.0.1-SNAPSHOT</version></dependency><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alicloud-oss</artifactId></dependency><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-alibaba-dependencies</artifactId><version>2.1.0.RELEASE</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement>
package com.xd.cubemall.thirdparty;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;@EnableDiscoveryClient
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class CubemallThirdPartyApplication {public static void main(String[] args) {SpringApplication.run(CubemallThirdPartyApplication.class, args);}}
package com.xd.cubemall.thirdparty;import com.aliyun.oss.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import com.aliyun.oss.model.PutObjectRequest;
import com.aliyun.oss.model.PutObjectResult;
import org.springframework.test.context.junit4.SpringRunner;import java.io.FileInputStream;
import java.io.InputStream;@RunWith(SpringRunner.class)
@SpringBootTest
public class CubemallThirdPartyApplicationTests {@Autowiredprivate OSSClient ossClient;@Testpublic void test() throws Exception{// 填写Bucket名称,例如examplebucket。String bucketName = "";// 填写Object完整路径,完整路径中不能包含Bucket名称,例如exampledir/exampleobject.txt。String objectName = "";// 填写本地文件的完整路径,例如D:\\localpath\\examplefile.txt。// 如果未指定本地路径,则默认从示例程序所属项目对应本地路径中上传文件流。String filePath= "";try {InputStream inputStream = new FileInputStream(filePath);// 创建PutObjectRequest对象。PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectName, inputStream);// 创建PutObject请求。PutObjectResult result = ossClient.putObject(putObjectRequest);} catch (OSSException oe) {System.out.println("Caught an OSSException, which means your request made it to OSS, "+ "but was rejected with an error response for some reason.");System.out.println("Error Message:" + oe.getErrorMessage());System.out.println("Error Code:" + oe.getErrorCode());System.out.println("Request ID:" + oe.getRequestId());System.out.println("Host ID:" + oe.getHostId());} catch (ClientException ce) {System.out.println("Caught an ClientException, which means the client encountered "+ "a serious internal problem while trying to communicate with OSS, "+ "such as not being able to access the network.");System.out.println("Error Message:" + ce.getMessage());} finally {if (ossClient != null) {ossClient.shutdown();}}System.out.println("上传成功");}}

服务端签名直传

1 用户发送上传Policy请求到应用服务器
2 应用服务器返回上传Policy和签名给用户
3 用户直接上传数据到OSS

http://127.0.0.1:30000/oss/policy
http://127.0.0.1:8888/api/thirdparty/oss/policy
      <template slot-scope="scope"><el-buttonsize="mini"@click="handleEdit(scope.$index, scope.row)">编辑</el-button><el-buttonsize="mini"type="danger"@click="handleDelete(scope.$index, scope.row)">删除</el-button></template>
    <el-imagestyle="width: 100px; height: 100px":src="url":fit="fit"></el-image>

前端

上传组件

src/components/upload

policy.js

import http from '@/utils/httpRequest.js'
export function policy() {return  new Promise((resolve,reject)=>{http({url: http.adornUrl("/thirdparty/oss/policy"),method: "get",params: http.adornParams({})}).then(({ data }) => {resolve(data);})});
}

singleUpload.vue

<template> <div><el-uploadaction="https://cubemall-product.oss-cn-shanghai.aliyuncs.com":data="dataObj"list-type="picture":multiple="false" :show-file-list="showFileList":file-list="fileList":before-upload="beforeUpload":on-remove="handleRemove":on-success="handleUploadSuccess":on-preview="handlePreview"><el-button size="small" type="primary">点击上传</el-button><div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过10MB</div></el-upload><el-dialog :visible.sync="dialogVisible"><img width="100%" :src="fileList[0].url" alt=""></el-dialog></div>
</template>
<script>import {policy} from './policy'import { getUUID } from '@/utils'export default {name: 'singleUpload',props: {value: String},computed: {imageUrl() {return this.value;},imageName() {if (this.value != null && this.value !== '') {return this.value.substr(this.value.lastIndexOf("/") + 1);} else {return null;}},fileList() {return [{name: this.imageName,url: this.imageUrl}]},showFileList: {get: function () {return this.value !== null && this.value !== ''&& this.value!==undefined;},set: function (newValue) {}}},data() {return {dataObj: {policy: '',signature: '',key: '',ossaccessKeyId: '',dir: '',host: '',// callback:'',},dialogVisible: false};},methods: {emitInput(val) {this.$emit('input', val)},handleRemove(file, fileList) {this.emitInput('');},handlePreview(file) {this.dialogVisible = true;},beforeUpload(file) {let _self = this;return new Promise((resolve, reject) => {policy().then(response => {console.log("响应的数据",response);_self.dataObj.policy = response.data.policy;_self.dataObj.signature = response.data.signature;_self.dataObj.ossaccessKeyId = response.data.accessid;_self.dataObj.key = response.data.dir +getUUID()+'_${filename}';_self.dataObj.dir = response.data.dir;_self.dataObj.host = response.data.host;console.log("响应的数据222。。。",_self.dataObj);resolve(true)}).catch(err => {reject(false)})})},handleUploadSuccess(res, file) {console.log("上传成功...")this.showFileList = true;this.fileList.pop();this.fileList.push({name: file.name, url: this.dataObj.host + '/' + this.dataObj.key.replace("${filename}",file.name) });this.emitInput(this.fileList[0].url);}}}
</script>
<style></style>

brand-add-or-update.vue

src/views/modules/product


<template><el-dialog:title="!dataForm.id ? '新增' : '修改'":close-on-click-modal="false":visible.sync="visible"><el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="130px"><el-form-item label="品牌名称" prop="name"><el-input v-model="dataForm.name" placeholder="品牌名称"></el-input></el-form-item><el-form-item label="品牌图片地址" prop="image"><!-- <el-input v-model="dataForm.image" placeholder="品牌图片地址"></el-input> --><single-upload v-model="dataForm.image" ></single-upload></el-form-item><el-form-item label="品牌的首字母" prop="letter"><el-input v-model="dataForm.letter" placeholder="品牌的首字母"></el-input></el-form-item><el-form-item label="排序" prop="seq"><el-input v-model="dataForm.seq" placeholder="排序"></el-input></el-form-item></el-form><span slot="footer" class="dialog-footer"><el-button @click="visible = false">取消</el-button><el-button type="primary" @click="dataFormSubmit()">确定</el-button></span></el-dialog>
</template><script>import SingleUpload from "@/components/upload/singleUpload";
// import SingleUpload from '../../../components/upload/singleUpload.vue';export default {components: {SingleUpload},data () {return {visible: false,dataForm: {id: 0,name: '',image: '',letter: '',seq: ''},dataRule: {name: [{ required: true, message: '品牌名称不能为空', trigger: 'blur' }],image: [{ required: true, message: '品牌图片地址不能为空', trigger: 'blur' }],letter: [{ required: true, message: '品牌的首字母不能为空', trigger: 'blur' }],seq: [{ required: true, message: '排序不能为空', trigger: 'blur' }]}}},methods: {init (id) {this.dataForm.id = id || 0this.visible = truethis.$nextTick(() => {this.$refs['dataForm'].resetFields()if (this.dataForm.id) {this.$http({url: this.$http.adornUrl(`/product/brand/info/${this.dataForm.id}`),method: 'get',params: this.$http.adornParams()}).then(({data}) => {if (data && data.code === 0) {this.dataForm.name = data.brand.namethis.dataForm.image = data.brand.imagethis.dataForm.letter = data.brand.letterthis.dataForm.seq = data.brand.seq}})}})},// 表单提交dataFormSubmit () {this.$refs['dataForm'].validate((valid) => {if (valid) {this.$http({url: this.$http.adornUrl(`/product/brand/${!this.dataForm.id ? 'save' : 'update'}`),method: 'post',data: this.$http.adornData({'id': this.dataForm.id || undefined,'name': this.dataForm.name,'image': this.dataForm.image,'letter': this.dataForm.letter,'seq': this.dataForm.seq})}).then(({data}) => {if (data && data.code === 0) {this.$message({message: '操作成功',type: 'success',duration: 1500,onClose: () => {this.visible = falsethis.$emit('refreshDataList')}})} else {this.$message.error(data.msg)}})}})}}}
</script>

brand.vue


<template><div class="mod-config"><el-form:inline="true":model="dataForm"@keyup.enter.native="getDataList()"><el-form-item><el-inputv-model="dataForm.key"placeholder="参数名"clearable></el-input></el-form-item><el-form-item><el-button @click="getDataList()">查询</el-button><el-buttonv-if="isAuth('product:brand:save')"type="primary"@click="addOrUpdateHandle()">新增</el-button><el-buttonv-if="isAuth('product:brand:delete')"type="danger"@click="deleteHandle()":disabled="dataListSelections.length <= 0">批量删除</el-button></el-form-item></el-form><el-table:data="dataList"borderv-loading="dataListLoading"@selection-change="selectionChangeHandle"style="width: 100%"><el-table-columntype="selection"header-align="center"align="center"width="50"></el-table-column><el-table-columnprop="id"header-align="center"align="center"label="品牌id"></el-table-column><el-table-columnprop="name"header-align="center"align="center"label="品牌名称"></el-table-column><el-table-columnprop="image"header-align="center"align="center"label="品牌图片地址"><template slot-scope="scope"><img style="width: 100px; height: 100px" :src="scope.row.image"/></template></el-table-column><el-table-columnprop="letter"header-align="center"align="center"label="品牌的首字母"></el-table-column><el-table-columnprop="seq"header-align="center"align="center"label="排序"></el-table-column><el-table-columnfixed="right"header-align="center"align="center"width="150"label="操作"><template slot-scope="scope"><el-buttontype="text"size="small"@click="addOrUpdateHandle(scope.row.id)">修改</el-button><el-buttontype="text"size="small"@click="deleteHandle(scope.row.id)">删除</el-button></template></el-table-column></el-table><el-pagination@size-change="sizeChangeHandle"@current-change="currentChangeHandle":current-page="pageIndex":page-sizes="[10, 20, 50, 100]":page-size="pageSize":total="totalPage"layout="total, sizes, prev, pager, next, jumper"></el-pagination><!-- 弹窗, 新增 / 修改 --><add-or-updatev-if="addOrUpdateVisible"ref="addOrUpdate"@refreshDataList="getDataList"></add-or-update></div>
</template><script>
import AddOrUpdate from "./brand-add-or-update";
export default {data() {return {dataForm: {key: "",},dataList: [],pageIndex: 1,pageSize: 10,totalPage: 0,dataListLoading: false,dataListSelections: [],addOrUpdateVisible: false,};},components: {AddOrUpdate,},activated() {this.getDataList();},methods: {// 获取数据列表getDataList() {this.dataListLoading = true;this.$http({url: this.$http.adornUrl("/product/brand/list"),method: "get",params: this.$http.adornParams({page: this.pageIndex,limit: this.pageSize,key: this.dataForm.key,}),}).then(({ data }) => {if (data && data.code === 0) {this.dataList = data.page.list;this.totalPage = data.page.totalCount;} else {this.dataList = [];this.totalPage = 0;}this.dataListLoading = false;});},// 每页数sizeChangeHandle(val) {this.pageSize = val;this.pageIndex = 1;this.getDataList();},// 当前页currentChangeHandle(val) {this.pageIndex = val;this.getDataList();},// 多选selectionChangeHandle(val) {this.dataListSelections = val;},// 新增 / 修改addOrUpdateHandle(id) {this.addOrUpdateVisible = true;this.$nextTick(() => {this.$refs.addOrUpdate.init(id);});},// 删除deleteHandle(id) {var ids = id? [id]: this.dataListSelections.map((item) => {return item.id;});this.$confirm(`确定对[id=${ids.join(",")}]进行[${id ? "删除" : "批量删除"}]操作?`,"提示",{confirmButtonText: "确定",cancelButtonText: "取消",type: "warning",}).then(() => {this.$http({url: this.$http.adornUrl("/product/brand/delete"),method: "post",data: this.$http.adornData(ids, false),}).then(({ data }) => {if (data && data.code === 0) {this.$message({message: "操作成功",type: "success",duration: 1500,onClose: () => {this.getDataList();},});} else {this.$message.error(data.msg);}});});},},
};
</script>

index.js

static/config/

/*** 开发环境*/
;(function () {window.SITE_CONFIG = {};// api接口请求地址window.SITE_CONFIG['baseUrl'] = 'http://localhost:8888/api';// cdn地址 = 域名 + 版本号window.SITE_CONFIG['domain']  = './'; // 域名window.SITE_CONFIG['version'] = '';   // 版本号(年月日时分)window.SITE_CONFIG['cdnUrl']  = window.SITE_CONFIG.domain + window.SITE_CONFIG.version;
})();

后端

cubemall-gateway

application.yml

spring:cloud:gateway:routes:- id: baidu_routeuri: https://www.baidu.compredicates:- Query=url, baidu- id: qq_routeuri: https://www.qq.compredicates:- Query=url, qq- id: product_routeuri: lb://cubemall-productpredicates:- Path=/api/product/**filters:- RewritePath=/api/(?<segment>/?.*), /$\{segment}- id: third-party_routeuri: lb://cubemall-third-partypredicates:- Path=/api/thirdparty/**filters:- RewritePath=/api/thirdparty/(?<segment>/?.*), /$\{segment}- id: admin_routeuri: lb://renren-fastpredicates:- Path=/api/**filters:- RewritePath=/api/(?<segment>/?.*), /renren-fast/$\{segment}

cubemall-third-party

OssController.java

package com.xd.cubemall.thirdparty.controller;import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.common.utils.BinaryUtil;
import com.aliyun.oss.model.MatchMode;
import com.aliyun.oss.model.PolicyConditions;
import com.xd.cubemall.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;@RestController
public class OssController {@Autowiredprivate OSS ossClient;@Value("${spring.cloud.alicloud.access-key}")private String accessId; // 请填写您的AccessKeyId。@Value("${spring.cloud.alicloud.secret-key}")private String accessKey; // 请填写您的AccessKeySecret。@Value("${spring.cloud.alicloud.oss.endpoint}")private String endpoint; // 请填写您的 endpoint。String bucket = "cubemall-product"; // 请填写您的 bucketname 。@RequestMapping("/oss/policy")public R policy(){String host = "https://" + bucket + "." + endpoint; // host的格式为 bucketname.endpoint// callbackUrl为 上传回调服务器的URL,请将下面的IP和Port配置为您自己的真实信息。String format = new SimpleDateFormat("yyyy-MM-dd").format(new Date());String dir = format+"/"; // 用户上传文件时指定的前缀。Map<String, String> respMap = null;try {long expireTime = 30;long expireEndTime = System.currentTimeMillis() + expireTime * 1000;Date expiration = new Date(expireEndTime);// PostObject请求最大可支持的文件大小为5 GB,即CONTENT_LENGTH_RANGE为5*1024*1024*1024。PolicyConditions policyConds = new PolicyConditions();policyConds.addConditionItem(PolicyConditions.COND_CONTENT_LENGTH_RANGE, 0, 1048576000);policyConds.addConditionItem(MatchMode.StartWith, PolicyConditions.COND_KEY, dir);String postPolicy = ossClient.generatePostPolicy(expiration, policyConds);byte[] binaryData = postPolicy.getBytes("utf-8");String encodedPolicy = BinaryUtil.toBase64String(binaryData);String postSignature = ossClient.calculatePostSignature(postPolicy);respMap = new LinkedHashMap<String, String>();respMap.put("accessid", accessId);respMap.put("policy", encodedPolicy);respMap.put("signature", postSignature);respMap.put("dir", dir);respMap.put("host", host);respMap.put("expire", String.valueOf(expireEndTime / 1000));} catch (Exception e) {System.out.println(e.getMessage());} finally {ossClient.shutdown();}return R.ok().put("data", respMap);}
}

CubemallThirdPartyApplication.java

package com.xd.cubemall.thirdparty;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;@EnableDiscoveryClient
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class CubemallThirdPartyApplication {public static void main(String[] args) {SpringApplication.run(CubemallThirdPartyApplication.class, args);}}

application.yml

spring:cloud:nacos:discovery:server-addr: 127.0.0.1:8848alicloud:oss:endpoint: oss-cn-shanghai.aliyuncs.comaccess-key: secret-key: application:name: cubemall-third-party
server:port: 30000

pom.xml

<dependencies><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alicloud-oss</artifactId></dependency>
</dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-alibaba-dependencies</artifactId><version>2.1.0.RELEASE</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement>

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 自动化开发流程:使用 GitHub Actions 进行 CI/CD
  • 使用 Dify 和 AI 大模型理解视频内容:Qwen 2 VL 72B
  • React+Vis.js(05):vis.js的节点的点击事件
  • 主机安全-网络攻击监测
  • 观测云对接 Pinpoint 最佳实践
  • 设备运维故障排查与修复技巧
  • 宝塔面板配置node/npm/yarn/pm2....相关全局变量 npm/node/XXX: command not found
  • Kafka的基本概念
  • 适用于 Windows 10 的最佳数据恢复免费软件是什么?
  • [JAVA] 什么是Java线程同步机制?
  • BIO,NIO,AIO编程实战
  • 游戏开发设计模式之责任链模式
  • MyBatis 源码解析:配置文件结构与自定义实现详解
  • 等保测评入门
  • VScode误删文件恢复或恢复之前版本记录
  • [译]CSS 居中(Center)方法大合集
  • C++入门教程(10):for 语句
  • create-react-app做的留言板
  • Java应用性能调优
  • TypeScript实现数据结构(一)栈,队列,链表
  • underscore源码剖析之整体架构
  • yii2中session跨域名的问题
  • 创建一种深思熟虑的文化
  • 高度不固定时垂直居中
  • 开年巨制!千人千面回放技术让你“看到”Flutter用户侧问题
  • 罗辑思维在全链路压测方面的实践和工作笔记
  • 浅谈Kotlin实战篇之自定义View图片圆角简单应用(一)
  • 入职第二天:使用koa搭建node server是种怎样的体验
  • 算法系列——算法入门之递归分而治之思想的实现
  • 项目实战-Api的解决方案
  • 移动端解决方案学习记录
  • 远离DoS攻击 Windows Server 2016发布DNS政策
  • ​力扣解法汇总1802. 有界数组中指定下标处的最大值
  • ​一帧图像的Android之旅 :应用的首个绘制请求
  • #NOIP 2014# day.1 T2 联合权值
  • (1)svelte 教程:hello world
  • (8)STL算法之替换
  • (DenseNet)Densely Connected Convolutional Networks--Gao Huang
  • (动手学习深度学习)第13章 计算机视觉---微调
  • (附源码)计算机毕业设计高校学生选课系统
  • (佳作)两轮平衡小车(原理图、PCB、程序源码、BOM等)
  • (力扣记录)1448. 统计二叉树中好节点的数目
  • (没学懂,待填坑)【动态规划】数位动态规划
  • (算法)区间调度问题
  • (一)基于IDEA的JAVA基础10
  • (转)c++ std::pair 与 std::make
  • (转)Google的Objective-C编码规范
  • (轉貼) 蒼井そら挑戰筋肉擂台 (Misc)
  • .gitignore文件设置了忽略但不生效
  • .net 4.0发布后不能正常显示图片问题
  • .NET Core 和 .NET Framework 中的 MEF2
  • .NET Framework 服务实现监控可观测性最佳实践
  • .NET HttpWebRequest、WebClient、HttpClient
  • .Net Memory Profiler的使用举例
  • .NET程序员迈向卓越的必由之路