BAEL-4564 fixed code formatting
This commit is contained in:
parent
9089307991
commit
8e5ebe813c
|
@ -2,7 +2,6 @@ package com.baeldung.filtersinterceptors;
|
|||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
|
||||
@SpringBootApplication(scanBasePackages = "com.baeldung.filtersinterceptors")
|
||||
public class FilterInterceptorApp {
|
||||
|
|
|
@ -7,13 +7,13 @@ import org.springframework.web.bind.annotation.GetMapping;
|
|||
|
||||
@Controller
|
||||
public class HelloConroller {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(HelloConroller.class);
|
||||
|
||||
@GetMapping("/hello")
|
||||
public String hello() {
|
||||
logger.info("Hello from the controller");
|
||||
return "hello";
|
||||
}
|
||||
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(HelloConroller.class);
|
||||
|
||||
@GetMapping("/hello")
|
||||
public String hello() {
|
||||
logger.info("Hello from the controller");
|
||||
return "hello";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,13 +15,12 @@ import org.springframework.stereotype.Component;
|
|||
@Component
|
||||
public class LogFilter implements Filter {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(LogFilter.class);
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
||||
throws IOException, ServletException {
|
||||
logger.info("Hello from: "+request.getLocalAddr());
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
private Logger logger = LoggerFactory.getLogger(LogFilter.class);
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
||||
logger.info("Hello from: " + request.getLocalAddr());
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,28 +9,24 @@ import org.springframework.stereotype.Component;
|
|||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
@Component
|
||||
public class LogInterceptor implements HandlerInterceptor{
|
||||
public class LogInterceptor implements HandlerInterceptor {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(LogInterceptor.class);
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
logger.info("preHandle");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
|
||||
logger.info("postHandle");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
|
||||
logger.info("afterCompletion");
|
||||
}
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(LogInterceptor.class);
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
|
||||
throws Exception {
|
||||
logger.info("preHandle");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
|
||||
ModelAndView modelAndView) throws Exception {
|
||||
logger.info("postHandle");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
|
||||
throws Exception {
|
||||
logger.info("afterCompletion");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,17 +5,11 @@ import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class WebMvcConfig implements WebMvcConfigurer {
|
||||
public class WebMvcConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(new LogInterceptor());
|
||||
}
|
||||
|
||||
private final LogInterceptor logInterceptor;
|
||||
|
||||
public WebMvcConfig(LogInterceptor logInterceptor) {
|
||||
this.logInterceptor = new LogInterceptor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(logInterceptor).addPathPatterns("/**");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue