slf4j 기본적으로 Spring은 akarta Commons Logging API (JCL)을 사용한다. [JCL] if (logger.isdebugenabled()) { logger.debug("log test " + String.valueOf(1) + "count.");} [SLF4J] logger.debug("log test {} count", 1); : 스트링 계산을 할 필요가 없다. slf4j, logback maven 123456789101112131415161718 org.slf4j slf4j-api 1.7.7 ch.qos.logback logback-classic 1.1.2 org.slf4j slf4j-api : slf4j는 인터페이스며, 이를 구현해주는 logback을 사용한다. : logging.. Backend/Spring 8년 전
ExceptionHandler view plaincopy to clipboardprint?package com.ekiras.handler.exception; import com.ekiras.exception.BaseException; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation... Backend/Spring 8년 전
요청방식 세분화 1. 조회는 Get2. 변경은 Post @RestController@RequestMapping("/scout/posting")public class PostingController { Logger log = Logger.getLogger(this.getClass()); @Autowired private PostingService postingService; @RequestMapping(value = { "", "/" }, method = RequestMethod.GET) public PostView post(@RequestParam("teamId") int teamId) { return postingService.getPostView(teamId); } @RequestMapping(value = "/bi.. Backend/Spring 8년 전
afterPropertiesSet 생성자에서는 빈, 환경변수 주입이 되지 않았기 때문에 멤버변수, 환경변수를 사용하려면 afterPropertiesSet을 사용하여야 한다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30public class GoogleAuthServiceImpl implements GoogleAuthService, InitializingBean { private static final JsonFactory JSON_FACTORY = new JacksonFactory(); private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport(); @Setter pr.. Backend/Spring 8년 전
@ConfigurationProperties 1. Value("")는 complex object를 사용할 수 없다. Spring Boot provides a very neat way to load properties for an application. Consider a set of properties described using YAML format:prefix: stringProp1: propValue1 stringProp2: propValue2 intProp1: 10 listProp: - listValue1 - listValue2 mapProp: key1: mapValue1 key2: mapValue2It has taken me a little while, but I do like the hierarchical look of the prope.. Backend/Spring 8년 전
Custom Annotation 주석의 경우 컴파일 시 모두 지워 지지만 @Retention(RetentionPolicy.RUNTIME)을 통해서 어노테이션은 컴파일 시 지워지지 않아, 런타임 시 사용할 수 있다. package com.aceproject.game.common.util; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface ExcelMapping .. Backend/Spring 8년 전