当前位置:网站首页>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 ");
}
}
边栏推荐
- (mandatory) override equals must override hashcode (principle analysis)
- 深入解析著名的阿里云Log4j 漏洞
- Trends of semiconductor industry
- 生信常用分析图形绘制02 -- 解锁火山图真谛!
- Common questions of testers during interview
- 阿里巴巴/166获得店铺的所有商品 API使用说明
- [network security] analysis vulnerability of website Middleware
- C语言自定义类型讲解 — 联合体
- 700. Search DFS method in binary search tree
- 213. Looting II - Dynamic Planning
猜你喜欢

es(1)

Common methods of number and math classes

The ability to detect movement in vivo and build a safe and reliable payment level "face brushing" experience

In the morning, Tencent took out 38K, which let me see the ceiling of the foundation

Huawei machine test - topic core test point

ShardingSphere数据库读写分离

C语言中的字符与字符串库函数的使用以及模拟实现

C language custom type explanation - Consortium

Getaverse, a distant bridge to Web3

Step by step introduction to the development framework based on sqlsugar (12) -- split the content of the page module into components to realize the division and rule processing
随机推荐
Awk from entry to earth (17) awk multiline writing
近30所高校,获教育部点名表扬!
SSM framework learning
使用matplotlib模拟线性回归
Tensorflow introductory tutorial (37) -- DC Vnet
0629~SaaS平台设计~全局异常处理
Can Lu Zhengyao hide from the live broadcast room dominated by Luo min?
C language to achieve a static version of the address book
DHCP relay of HCNP Routing & Switching
(mandatory) override equals must override hashcode (principle analysis)
20 -- validate palindrome string
DF2NET三维模型部署
C language custom type explanation - Consortium
awk从入门到入土(19)awk扩展插件,让awk如虎添翼
com.mysql.cj.jdbc.exceptions. MySQLTransactionRollbackException: Deadlock found when trying to get lo
Opencv picture rotation
Tensorflow introductory tutorial (38) -- V2 net
Extension of ES6 function
1688/阿里巴巴按关键字搜索新品数据 API 使用说明
C language custom type explanation - structure