본문 바로가기

IT/Spring

(40)
[SpringBoot] destroy event 등록하기 spring boot를 사용하다보면 명시적으로 자원을 close 해주어야 하는 경우가 있습니다. 이때 spring boot destory event 발생 시 자원을 close해주는 코드를 추가해주면 됩니다. public class ShutdownHookConfiguration { public void destroy() { /* close 로직*/ } } import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; @SpringBootApplication publ..
[Spring Boot] 간단하게 @Scheduled 사용하기 1. @Scheduled 어노테이션 특정 메소드에 @Scheduled 어노테이션을 선언하면 설정한 값에 따라 주기적으로 해당 메소드를 실행시킬 수 있습니다. 2. @Scheduled 사용 방법 1) 스프링 스케줄링 기능 활성화 import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.scheduling.annotation.EnableScheduling; @SpringBootApplication @EnableScheduling public class MyApplication { public static ..
[Spring Boot] thymeleaf 사용방법 1. Thymeleaf 란 Thymeleaf는 View Template Engine입니다. 그리고 컨트롤러에서 전달받은 데이터를 이용해 동적인 페이지를 만들 수 있습니다. 태그의 속성으로 thymeleaf 명령어를 사용할 수 있으며 html 파일 내에서 사용이 가능합니다. 2. Thymeleaf 적용 spring boot 2.2.2.RELEASE 버전에서 테스트한 내용입니다. thymeleaf의 default prefix는 src/main/resources/templates이며 suffix는 .html입니다. 1) dependency (pom.xml) ... org.springframework.boot spring-boot-starter-thymeleaf ... 2) Controller import ja..
[Spring] thymeleaf-layout-dialect WARN 해결 2021-02-15 16:28:54 [http-nio-8080-exec-79] [WARN ] n.n.u.t.d.DecoratorProcessor - The layout:decorator/data-layout-decorator processor has been deprecated and will be removed in the next major version of the layout dialect. Please use layout:decorate/data-layout-decorate instead to future-proof your code. See https://github.com/ultraq/thymeleaf-layout-dialect/issues/95 for more information. 202..
[Spring] 의존성 주입(Dependency Inject,DI)이란? 의존성 주입을 이해하기 전에 의존성에 대해서 먼저 알아보겠습니다. 1. 의존성이란? 의존의 사전적 의미는 "스스로 하지 못하고 누군가에게 도움을 받음" 입니다. 그렇다면 의존성은 무엇일까요? 의존성이란 어떤 객체가 생성되기 위해 다른 객체가 꼭 필요한 상태를 의미합니다. 의존성은 new 연산자를 통해 발생합니다. 의존성이 높아지면 결합도 또한 높아집니다. 결합도가 높으면 해당 클래스를 수정할 경우 참조하고 있는 다른 클래스도 함께 이해해야합니다. 왜냐하면 무작정 수정했다가는 사이드 이펙트가 발생할 수 있기 때문입니다. 그리고 결합도가 높은 클래스는 재사용하기 힘듭니다. 1) 의존성 예제 public class Windows { public void booting() { System.out.println(..
[Spring Boot] Hikari Connection Pool 설정 hikariCP는 SpringBoot2.0부터 default JDBC connection pool로 지정된 DBCP(Database Connection Pool)입니다. hikariCP는 다른 DBCP보다 성능이 좋다고 합니다. 자세한 내용은 github.com/brettwooldridge/HikariCP에서 확인할 수 있습니다. DBCP란 2020/11/04 - [IT/데이터베이스] - DataSouce와 DBCP(DataBase Connection Pool)란 SpringBoot에서 아래와 같은 dependency를 추가해 주면 hikari DBCP가 default로 사용됩니다. org.springframework.boot spring-boot-starter-jdbc 스프링 부트 DBCP 설정 스프링..
[Spring Boot] 스프링 부트란 무엇인가? 1. 스프링 부트란? 스프링 프레임워크 기반 프로젝트를 복잡한 설정없이 쉽고 빠르게 만들어주는 라이브러리입니다. 사용자가 일일이 모든 설정을 하지 않아도 자주 사용되는 기본설정을 알아서 해줍니다. 2. 왜 스프링 부트를 사용해야할까? 스프링 프레임워크를 사용하려면 많은 XML 설정 파일(web.xml, rootContext.xml, ServletContext.xml 등)들을 작성해야하고, 설정 방법을 모두 외우지 못했다면 기존에 사용했던 설정을 Copy&Paste하거나 개발자가 일일이 인터넷 검색을 통해서 설정해주어야 했습니다. 이는 곧 생산성과 비용 문제로 직결될 수 있습니다. 하지만 스프링 부트를 사용하면 복잡한 설정없이 쉽고 빠르게 스프링 프레임워크를 사용할 수 있습니다. 3. Spring Boot..
[SpringBoot] HandlerInterceptor 설정하기 1. HandlerInterceptor 란? Spring Framework에서 지원하는 기능이며, URI 요청, 응답 시점을 가로채서 전/후 처리를 하는 역할을 합니다. Interceptor 시점에 Spring Context와 Bean에 접근할 수 있습니다. 이와 비슷한 역할로 Filter와 AOP가 있습니다. Filter는 Spring Framework와 무관하게 동작하며, Spring 자원을 이용할 수 없습니다. Filter는 보통 인코딩, XSS방어 등...의 용도로 이용됩니다. AOP는 주로 비즈니스 로직에서 실행됩니다. Logging, transaction 처리 등 중복 코드가 발생할 경우 중복을 줄이기 위해 사용되며, 메소드 처리 전후 지점에 자유롭게 설정이 가능합니다. 2. Filter, I..

반응형