Spring Boot core knowledge system
· Vue3 family bucket actual combat landing
· Standard front-end and back-end development model
Meet the mainstream
norms and standards of the enterprise
· Enterprise-level coding style
· Standardize Git operation and release process
· Supporting universal front and rear components + tools
Comprehensive technical application, detailed explanation is only
Solve the problem of front-end separation
Front-end and back-end function integration, integrated HTTP component Axios, to solve common problems in the front-end and back-end separation architecture, such as cross-domain, parameter transfer, multi-environment configuration, etc.
Landing practical engineering projects
Covers logs, configuration files, hot deployment, Git, Maven, back-end interface unified return parameter design, package unified request return parameters, tool class package
Spring Boot core skills
AOP, interceptors, filters, asynchronization, timing tasks, WebSocket, caching, message queues, exception handling, multiple environments, etc.
Summarize and sort out high-frequency interview questions
After each chapter, the knowledge will be sorted out, and the classic high-frequency interview questions will be discussed together, so that the knowledge will be more firmly grasped and the interview will be more effective.
We have learned to integrate Filter in Spring , essentially registering Spring-managed Beans in the Servlet container through a proxy, but the steps are more cumbersome and require configuration web.xml
.
In Spring Boot, adding one Filter
is simpler and can achieve zero configuration. Let's take a look at how to add in Spring Boot Filter
.
Spring Boot will automatically scan all FilterRegistrationBean
types of Beans, and then Filter
automatically register them in the Servlet container without any configuration.
Let's take AuthFilter
an example and write one first AuthFilterRegistrationBean
, it inherits from FilterRegistrationBean
:
@Order(10)
@Component
public class AuthFilterRegistrationBean extends FilterRegistrationBean<Filter> {
@Autowired
UserService userService;
@Override
public Filter getFilter() {
return new AuthFilter();
}
class AuthFilter implements Filter {
...
}
}
FilterRegistrationBean
Not Filter
in itself , it is actually Filter
a factory. Spring Boot will call getFilter()
and Filter
register the returned to the Servlet container. Because we can FilterRegistrationBean
inject the required resources in, and then, in the return AuthFilter
, this inner class can reference all the fields of the outer class, naturally including the injected ones UserService
, so the whole process is completely based on Spring's IoC container.
Note that one is AuthFilterRegistrationBean
marked again @Order(10)
, because Spring Boot supports multiple Filter
sorts, with the smallest number in the front, so the multiple Filter
order can be fixed.
Let's write another one ApiFilter
specifically to filter /api/*
such URLs. First write aApiFilterRegistrationBean
@Order(20)
@Component
public class ApiFilterRegistrationBean extends FilterRegistrationBean<Filter> {
@PostConstruct
public void init() {
setFilter(new ApiFilter());
setUrlPatterns(List.of("/api/*"));
}
class ApiFilter implements Filter {
...
}
}
Link: https://pan.baidu.com/s/1y4PcAIwc4RtNPFqyvuYk6g
Extraction code: hk8v
Let's study hard together, come on.