当前位置:网站首页>0629 ~ SaaS platform design ~ global exception handling
0629 ~ SaaS platform design ~ global exception handling
2022-07-24 17:48:00 【Life is so hard】
SaaS Design concept :SaaS by Service providers provide a series of basic network construction , Operation and maintenance , Leasing and other services , According to actual needs , Provide services to service providers , Use the Internet to use the system , It makes the service provider as easy to use as turning on their own faucet , convenient ;
SaaS The best model :
Shared database , Shared data architecture , Use foreign keys to distinguish data
advantage : Use value cost is the lowest , It can store multiple tables , Many libraries , Store multiple data ;
shortcoming : Low isolation , Low security ; Data backup and recovery are difficult ;
Use in actual microservice scenarios feign:
remember : Which microservices need to expose interfaces to other services , Just draw the interface into one feign modular , Whoever needs to call will introduce the module ;
Use cases :
1. Import dependence ;
2. To write feign Interface ;
3. To write feign Implementation class of interface (fallbackFactory)
1. Import dependence ;
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> </dependency>
2. To write feign Interface ;
@FeignClient(value = "service-auth",fallbackFactory = FallbackAuth.class)
public interface FeignAuth {
@PostMapping(value="/login/save")
public JSONResult save(@RequestBody Login login);
@PostMapping(value="/saveLoginMeal")
public JSONResult saveLoginMealDto(@RequestBody LoginMealDto dto);
3. To write feign Implementation class of interface (fallbackFactory) Remember to give the implementation class to spring management
@Component
public class FallbackAuth implements FallbackFactory<FeignAuth> {
@Override
public FeignAuth create(Throwable throwable) {
return new FeignAuth() {
@Override
public JSONResult save(Login login) {
return JSONResult.error(" Registration information saving error ");
}
@Override
public JSONResult saveLoginMealDto(LoginMealDto dto) {
return JSONResult.error(" Registration information saving error dto");
}
};
}
}
Global exception handling
You can customize all exception classes for common system errors , Turn the error information into friendly information and return it to the user , Make users more clear and understandable ;
package cn.itsource.hrm.exception;
import cn.itsource.hrm.result.JSONResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;/**
* Global exception handling tool class
*/
@RestControllerAdvice // It's right Controller To enhance
public class GlobalExceptionHandler {// Catch and handle custom exceptions
@ExceptionHandler(MyException.class)
public JSONResult MyException(MyException e){
return JSONResult.error(e.getMessage());
}// Catch and handle arithmetic exceptions
@ExceptionHandler(ArithmeticException.class)
public JSONResult methodArithmeticException(ArithmeticException e){
return JSONResult.error(" Arithmetical abnormality ");
}/**
* If an exception not caught above occurs , So let's go through the exception capture , It is equivalent to the largest range
*/
@ExceptionHandler(Exception.class)
public JSONResult exceptionHandler(Exception e){
e.printStackTrace();
return JSONResult.error(" System exception , Please try again later ");
}
}
边栏推荐
- DF2NET三维模型部署
- Definition and storage of adjacency table and adjacency storage of directed graph and undirected graph
- Shardingsphere database read / write separation
- Blackmagic Fusion Studio 18
- 213. Looting II - Dynamic Planning
- 0614~放假自习
- 阿里巴巴1688按关键字搜索商品 API 使用展示
- PXE高效批量网络装机
- Trends of semiconductor industry
- mac数据库管理软件Navicat Premium Essentials Mac
猜你喜欢

Getaverse,走向Web3的远方桥梁

Gan Development Series II (pggan, Singan)

Mobile robot (IV) four axis aircraft

Ipaylinks, a cross-border payment integration service, won the 3A Asia Award of treasury

700. 二叉搜索树中的搜索-dfs法

2022 Asia International Internet of things exhibition

Shengxin commonly used analysis graphics drawing 02 -- unlock the essence of volcano map!

The results of the second quarter online moving people selection of "China Internet · moving 2022" were announced

es(1)

ShardingSphere数据库读写分离
随机推荐
SV强制类型转换和常数
船新 IDEA 2022.2 正式发布,新特性真香!
2022 Asia International Internet of things exhibition
Niuke linked list solution record
ShardingSphere数据库读写分离
Brats18 - Multimodal MR image brain tumor segmentation challenge continued
0613~自习
The use and Simulation of character and string library functions in C language
Trends of semiconductor industry
0701~放假总结
DF2NET三维模型部署
How to remove the top picture of the bubble skin article details of solo blog
Preliminary understanding of redis
Introduction and use of Pinia
awk从入门到入土(19)awk扩展插件,让awk如虎添翼
Wallys/3 × 3/2 × 2 MIMO 802.11ac Mini PCIe Wi-Fi Module, Dual Band, 2,4GHz / 5GHz/QCN9074
213. 打家劫舍 II-动态规划
Polymorphism, abstract class, interface
How the computer accesses the Internet (IV) LAN and server response
es(1)