Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Hsweb Framework | 8,047 | 1 | 12 days ago | 27 | June 20, 2022 | 3 | apache-2.0 | Java | ||
hsweb (haʊs wɛb) 是一个基于spring-boot 2.x开发 ,首个使用全响应式编程的企业级后台管理系统基础项目。 | ||||||||||
Tech Interview | 3,263 | 7 months ago | 13 | |||||||
:loudspeaker:🙍 tech interview | ||||||||||
Javacollection | 2,700 | 2 years ago | 3 | |||||||
Java开源项目之「自学编程之路」:学习指南+面试指南+资源分享+技术文章 | ||||||||||
Intellij Idea Tutorial | 2,094 | 5 months ago | mit | |||||||
🌻 This is a tutorial of IntelliJ IDEA, you can know how to use IntelliJ IDEA better and better. | ||||||||||
Ibase4j | 1,544 | 2 years ago | 17 | apache-2.0 | JavaScript | |||||
Spring,SpringBoot 2.0,SpringMVC,Mybatis,mybatis-plus,motan/dubbo分布式,Redis缓存,Shiro权限管理,Spring-Session单点登录,Quartz分布式集群调度,Restful服务,QQ/微信登录,App token登录,微信/支付宝支付;日期转换、数据类型转换、序列化、汉字转拼音、身份证号码验证、数字转人民币、发送短信、发送邮件、加密解密、图片处理、excel导入导出、FTP/SFTP/fastDFS上传下载、二维码、XML读写、高精度计算、系统配置工具类等等。 | ||||||||||
Spring Boot | 1,186 | 9 months ago | 13 | Java | ||||||
spring-boot 项目实践总结 | ||||||||||
Spring Mvc Quickstart Archetype | 1,016 | 4 years ago | 8 | Java | ||||||
The project is a Maven archetype for Spring MVC web application. | ||||||||||
Problem Spring Web | 919 | 2,422 | 21 | 16 days ago | 42 | November 09, 2021 | 39 | mit | Java | |
A library for handling Problems in Spring Web MVC | ||||||||||
Bestnote | 881 | a year ago | mit | |||||||
:punch: 持续更新,Java Android 近几年最全面的技术点以及面试题 供自己学习使用 | ||||||||||
Springmvcstepbystep | 760 | 6 months ago | 19 | mit | Java | |||||
Spring MVC Tutorial for beginners - In 25 Small Steps |
Problem Spring Web is a set of libraries that makes it easy to produce
application/problem+json
responses from a Spring
application. It fills a niche, in that it connects the Problem library and either
Spring Web MVC's exception handling
or Spring WebFlux's exception handling
so that they work seamlessly together, while requiring minimal additional developer effort. In doing so, it aims to
perform a small but repetitive task once and for all.
The way this library works is based on what we call advice traits. An advice trait is a small, reusable
@ExceptionHandler
implemented as a default method
placed in a single method interface. Those advice traits can be combined freely and don't require to use a common base
class for your @ControllerAdvice
.
🔎 Please check out Baeldung: A Guide to the Problem Spring Web Library for a detailed introduction!
The problem handling process provided by AdviceTrait
is built in a way that allows for customization whenever the
need arises. All of the following aspects (and more) can be customized by implementing the appropriate advice trait interface:
Aspect | Method(s) | Default |
---|---|---|
Creation | AdviceTrait.create(..) |
|
Logging | AdviceTrait.log(..) |
4xx as WARN , 5xx as ERROR including stack trace |
Content Negotiation | AdviceTrait.negotiate(..) |
application/json , application/*+json , application/problem+json and application/x.problem+json
|
Fallback | AdviceTrait.fallback(..) |
application/problem+json |
Post-Processing | AdviceTrait.process(..) |
n/a |
The following example customizes the MissingServletRequestParameterAdviceTrait
by adding a parameter
extension field to the Problem
:
@ControllerAdvice
public class MissingRequestParameterExceptionHandler implements MissingServletRequestParameterAdviceTrait {
@Override
public ProblemBuilder prepare(Throwable throwable, StatusType status, URI type) {
var exception = (MissingServletRequestParameterException) throwable;
return Problem.builder()
.withTitle(status.getReasonPhrase())
.withStatus(status)
.withDetail(exception.getMessage())
.with("parameter", exception.getParameterName());
}
}
Assuming there is a controller like this:
@RestController
@RequestMapping("/products")
class ProductsResource {
@RequestMapping(method = GET, value = "/{productId}", produces = APPLICATION_JSON_VALUE)
public Product getProduct(String productId) {
// TODO implement
return null;
}
@RequestMapping(method = PUT, value = "/{productId}", consumes = APPLICATION_JSON_VALUE)
public Product updateProduct(String productId, Product product) {
// TODO implement
throw new UnsupportedOperationException();
}
}
The following HTTP requests will produce the corresponding response respectively:
GET /products/123 HTTP/1.1
Accept: application/xml
HTTP/1.1 406 Not Acceptable
Content-Type: application/problem+json
{
"title": "Not Acceptable",
"status": 406,
"detail": "Could not find acceptable representation"
}
POST /products/123 HTTP/1.1
Content-Type: application/json
{}
HTTP/1.1 405 Method Not Allowed
Allow: GET
Content-Type: application/problem+json
{
"title": "Method Not Allowed",
"status": 405,
"detail": "POST not supported"
}
Before you continue, please read the section about Stack traces and causal chains in zalando/problem.
In case you want to enable stack traces, please configure your ProblemModule
as follows:
ObjectMapper mapper = new ObjectMapper()
.registerModule(new ProblemModule().withStackTraces());
Causal chains of problems are disabled by default, but can be overridden if desired:
@ControllerAdvice
class ExceptionHandling implements ProblemHandling {
@Override
public boolean isCausalChainsEnabled() {
return true;
}
}
Note Since you have full access to the application context at that point, you can externalize the
configuration to your application.yml
and even decide to reuse Spring's server.error.include-stacktrace
property.
Enabling both features, causal chains and stacktraces, will yield:
{
"title": "Internal Server Error",
"status": 500,
"detail": "Illegal State",
"stacktrace": [
"org.example.ExampleRestController.newIllegalState(ExampleRestController.java:96)",
"org.example.ExampleRestController.nestedThrowable(ExampleRestController.java:91)"
],
"cause": {
"title": "Internal Server Error",
"status": 500,
"detail": "Illegal Argument",
"stacktrace": [
"org.example.ExampleRestController.newIllegalArgument(ExampleRestController.java:100)",
"org.example.ExampleRestController.nestedThrowable(ExampleRestController.java:88)"
],
"cause": {
"title": "Internal Server Error",
"status": 500,
"detail": "Null Pointer",
"stacktrace": [
"org.example.ExampleRestController.newNullPointer(ExampleRestController.java:104)",
"org.example.ExampleRestController.nestedThrowable(ExampleRestController.java:86)",
"sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)",
"sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)",
"sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)",
"java.lang.reflect.Method.invoke(Method.java:483)",
"org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)",
"org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)",
"org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)",
"org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)",
"org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)",
"org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)",
"org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)",
"org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)",
"org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)",
"org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)",
"org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)",
"org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)",
"org.junit.runners.ParentRunner.run(ParentRunner.java:363)",
"org.junit.runner.JUnitCore.run(JUnitCore.java:137)",
"com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)",
"com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)",
"com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)"
]
}
}
}
Spring allows to restrict the scope of a @ControllerAdvice
to a certain subset of controllers:
@ControllerAdvice(assignableTypes = ExampleController.class)
public final class ExceptionHandling implements ProblemHandling
By doing this you'll loose the capability to handle certain types of exceptions namely:
HttpRequestMethodNotSupportedException
HttpMediaTypeNotAcceptableException
HttpMediaTypeNotSupportedException
NoHandlerFoundException
We inherit this restriction from Spring and therefore recommend to use an unrestricted @ControllerAdvice
.
If you have questions, concerns, bug reports, etc., please file an issue in this repository's Issue Tracker.
To contribute, simply make a pull request and add a brief description (1-2 sentences) of your addition or change. For more details, check the contribution guidelines.