2021-08-18
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Spring-boot Examples
|
||||
*
|
||||
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||
* https://www.elex-project.com/
|
||||
*/
|
||||
|
||||
package kr.pe.elex.examples;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.boot.web.servlet.ServletComponentScan;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@Slf4j
|
||||
@SpringBootApplication
|
||||
@ServletComponentScan
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FilterRegistrationBean<MyFilter3> myFilter(){
|
||||
FilterRegistrationBean<MyFilter3> bean = new FilterRegistrationBean<>();
|
||||
bean.setFilter(new MyFilter3());
|
||||
bean.setOrder(3);
|
||||
bean.addUrlPatterns("/sample/*");
|
||||
return bean;
|
||||
}
|
||||
}
|
||||
21
interceptor/src/main/java/kr/pe/elex/examples/MyConfig.java
Normal file
21
interceptor/src/main/java/kr/pe/elex/examples/MyConfig.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package kr.pe.elex.examples;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class MyConfig implements WebMvcConfigurer {
|
||||
@Autowired
|
||||
private MyInterceptor myInterceptor;
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
|
||||
registry.addInterceptor(myInterceptor)
|
||||
.addPathPatterns("/**");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Spring-boot Examples
|
||||
*
|
||||
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||
* https://www.elex-project.com/
|
||||
*/
|
||||
|
||||
package kr.pe.elex.examples;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.ContentDisposition;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@Slf4j
|
||||
@Controller
|
||||
public class MyController {
|
||||
@Autowired
|
||||
private MyService service;
|
||||
|
||||
@GetMapping(path = {"/**"})
|
||||
public String index() throws Exception {
|
||||
log.info("I'm a controller.");
|
||||
return "main";
|
||||
}
|
||||
|
||||
}
|
||||
19
interceptor/src/main/java/kr/pe/elex/examples/MyFilter1.java
Normal file
19
interceptor/src/main/java/kr/pe/elex/examples/MyFilter1.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package kr.pe.elex.examples;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.*;
|
||||
import java.io.IOException;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@Order(1)
|
||||
public class MyFilter1 implements Filter {
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
||||
log.info("I'm a filter 1.");
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
}
|
||||
20
interceptor/src/main/java/kr/pe/elex/examples/MyFilter2.java
Normal file
20
interceptor/src/main/java/kr/pe/elex/examples/MyFilter2.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package kr.pe.elex.examples;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.web.servlet.ServletComponentScan;
|
||||
import org.springframework.core.annotation.Order;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.annotation.WebFilter;
|
||||
import java.io.IOException;
|
||||
|
||||
@Slf4j
|
||||
@WebFilter(urlPatterns = "/sample/*")
|
||||
@Order(2)
|
||||
public class MyFilter2 implements Filter {
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
||||
log.info("I'm a filter 2.");
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
}
|
||||
17
interceptor/src/main/java/kr/pe/elex/examples/MyFilter3.java
Normal file
17
interceptor/src/main/java/kr/pe/elex/examples/MyFilter3.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package kr.pe.elex.examples;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.core.annotation.Order;
|
||||
|
||||
import javax.servlet.*;
|
||||
import java.io.IOException;
|
||||
|
||||
@Slf4j
|
||||
//@Order(3)
|
||||
public class MyFilter3 implements Filter {
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
||||
log.info("I'm a filter 3.");
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package kr.pe.elex.examples;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class MyInterceptor implements HandlerInterceptor {
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
log.info("I'm an interceptor, preHandle");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
|
||||
log.info("I'm an interceptor, postHandle");
|
||||
HandlerInterceptor.super.postHandle(request, response, handler, modelAndView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
|
||||
log.info("I'm an interceptor, afterCompletion");
|
||||
HandlerInterceptor.super.afterCompletion(request, response, handler, ex);
|
||||
}
|
||||
}
|
||||
10
interceptor/src/main/java/kr/pe/elex/examples/MyService.java
Normal file
10
interceptor/src/main/java/kr/pe/elex/examples/MyService.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package kr.pe.elex.examples;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class MyService {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
* Spring-boot Examples
|
||||
*
|
||||
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||
* https://www.elex-project.com/
|
||||
*/
|
||||
|
||||
package kr.pe.elex.examples;
|
||||
8
interceptor/src/main/resources/application.yaml
Normal file
8
interceptor/src/main/resources/application.yaml
Normal file
@@ -0,0 +1,8 @@
|
||||
spring:
|
||||
application:
|
||||
name: My spring-boot project
|
||||
server:
|
||||
port: 8080
|
||||
logging:
|
||||
level:
|
||||
root: info
|
||||
10
interceptor/src/main/resources/banner.txt
Normal file
10
interceptor/src/main/resources/banner.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
('-. ('-. ) (`-.
|
||||
_( OO) _( OO) ( OO ).
|
||||
(,------.,--. (,------.(_/. \_)-.
|
||||
| .---'| |.-') | .---' \ `.' /
|
||||
| | | | OO ) | | \ /\
|
||||
(| '--. | |`-' |(| '--. \ \ |
|
||||
| .--'(| '---.' | .--' .' \_)
|
||||
| `---.| | | `---. / .'. \
|
||||
`------'`------' `------''--' '--'
|
||||
powered by ELEX
|
||||
2
interceptor/src/main/resources/templates/main.mustache
Normal file
2
interceptor/src/main/resources/templates/main.mustache
Normal file
@@ -0,0 +1,2 @@
|
||||
<h1>Hello</h1>
|
||||
<p>Hello, World!</p>
|
||||
Reference in New Issue
Block a user