Category Archives: Spring

spring web 에서 파라미터를 전송할 때, 아무 이유 없이 파라미터 바인딩(parameter, bind, bound)이 되지 않았던 경우 (camel case, jackson)

By | 12월 13, 2022

전달되지 않은 파라미터 명: fInput 전달된 파라미터 명: ffInput ??? 원인 jackson이 java bean naming convention을 사용하는데, java 표준에는 ‘Don’t capitalize first two letters of a bean property name’ 라는 룰이 있다고 한다. 결국 jackson이 json parsing 하는 각 프로퍼티의 첫 두 글자는 무조건 소문자여야 한다는 것. 참고 https://stackoverflow.com/questions/30205006/why-does-jackson-2-not-recognize-the-first-capital-letter-if-the-leading-camel-c http://futuretask.blogspot.com/2005/01/java-tip-6-dont-capitalize-first-two.html

[펌글] SpringDoc (swagger 생성기) 을 노출하지 않기 (운영환경에서 필요할 듯)

By | 7월 4, 2022

Hi, This feature will be added on v1.2.12, of springdoc-openapi. This property helps you disable only the ui. springdoc.swagger-ui.enabled=false The following property, will help you disable the api-docs Rest endpoints as well: springdoc.api-docs.enabled=false 출처 https://github.com/springdoc/springdoc-openapi/issues/191

[링크] [java/spring] 쿼리 로그 출력시 파라미터 값이 바인딩된 채로 출력되게 하는 방법 (parameter bound query sql log) – log4jdbc-log4j2

By | 6월 23, 2022

https://rimkongs.tistory.com/312 이게 2013년 이후 업데이트가 끊긴 라이브러리라 최근에는 사용할 수 없을 거라고 막연히 생각했었는데, 웬걸, 2022년 지금도 잘 돌아가고 있는 모양이다. 괜히 p6spy 쓴다고 낑낑댄 건 아닌지 모르겠다. 심지어 이넘은 쿼리 결과도 테이블 모양으로 이쁘게 찍어준다.

spring boot jar 실행시 mybatis typeAlias 관련 오류 해결 (SpringBootVFS)

By | 4월 13, 2022

환경 springboot 2.6.3 mybatis-spring-boot-starter 2.2.2 mybatis 설정파일에 typeAlias 를 정의해 사용하고 있음. 서버 기동(springboot jar 파일 실행)시 에러메시지 org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias ‘[VO클래스명]’. Cause: java.lang.ClassNotFoundException: Cannot find class: [VO클래스명] 이 에러는 spring boot를 jar로 packaging하여 실행하는 경우에만 발생한다고 함. 해결 (xml config) 나는 설정의 편의를 위해 java config가… Read More »

org.apache.xerces.jaxp.SAXParserFactoryImpl cannot be cast to javax.xml.parsers.SAXParserFactory 오류 해결

By | 12월 10, 2021

환경 spring boot 1.5.22 (spring 4.3.25) JEUS 7 Fix#5 개요 잘 돌던 시스템이, apache poi를 pom에 추가한 시점부터 JEUS 서버 기동시 오류를 내뿜었다. (주로 logback.xml 을 읽지 못했다… 라는 내용의 로그였음) 해결 pom.xml > dependency > poi-ooxml 에 아래와 같이 exclusion 처리 추가 <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>3.9</version> <exclusions> <exclusion> <groupId>xml-apis</groupId> <artifactId>xml-apis</artifactId> </exclusion> </exclusions> </dependency> 출처… Read More »

springboot 환경설정 메모 (ver 1.5.22)

By | 9월 23, 2021

web환경 (servlet..)을 제거하는 설정 application.yml spring: main: web-environment: false spring security 를 제거하는 설정 기동 클래스 @SpringBootApplication(exclude = { SecurityAutoConfiguration.class }) application.yml security: basic: enabled: false management: security: enabled: false

Spring @Scheduled 스케쥴러 사용 샘플 (cron 표현식 등)

By | 8월 11, 2021

Spring Boot 라면 @EnableScheduling 을 붙여서 기본 셋팅이 가능한 것 같은데, 일반 Spring 에서는 아래와 같은 셋팅을 추가해 주어야 한다. thread pooling 관련 설정을 하기도 하는 것 같은데, 여기서는 가장 심플한 구성을 사용하기로 한다. spring context xml (‘task’ 가 포인트) <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"> <!–… Read More »

json 출력 혹은 swagger 문서에서 VO객체의 일부 필드(멤버) 숨기기 (Spring 4, jackson2, springfox 2.9 환경)

By | 6월 30, 2021

@ApiModelProperty(notes = "책 썸네일 atchFileId", hidden = true) @JsonIgnore private String bookThumbnailFileId; swagger의 모델 정의에서 필드 숨기기 @ApiModelProperty를 아예 필드에 붙이지 않는다. 모종의 이유로 붙였을 경우에는 @ApiModelProperty(hidden = true)를 사용한다. json response 에서 필드 숨기기 @JsonIgnore 를 사용한다. @JsonIgnore는 꼭 com.fasterxml.jackson.annotation.JsonIgnore 을 사용해야 한다. (java 패키지 확인)

[펌글] Spring Security 에서의 CORS 설정

By | 6월 29, 2021

spring security config 클래스 @EnableWebSecurity public class CustomSecurityConfig extends WebSecurityConfigurerAdapter { … @Override protected void configure(HttpSecurity http) throws Exception { http … .and() .authorizeRequests() .requestMatchers(CorsUtils::isPreFlightRequest).permitAll() // cors setting 1 … .and().cors(); // cors setting 2 } // cors setting 3 @Bean public CorsConfigurationSource corsConfigurationSource() { CorsConfiguration configuration = new CorsConfiguration(); // configuration.addAllowedOrigin("*"); configuration.addAllowedOrigin("http://localhost:3000"); configuration.addAllowedMethod("*"); configuration.addAllowedHeader("*");… Read More »

Spring 4 JUnit 테스트 샘플 코드 (Spring 4.3.16 기준, Spring boot 예제 아님)

By | 6월 14, 2021

pom.xml <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13.2</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>4.3.16</version> </dependency> TestJUnit.java package twopro; // 테스트코드에서도 log4j를 사용하고 싶다면 패키지는 꼭 필요한 듯. import cmm.jwt.TokenProvider; import lombok.extern.slf4j.Slf4j; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; /** * JUnit 테스트 * * @author 이프로 * @version 2021.06… Read More »

Spring 에서 @ResponseBody 로 json serialized response(응답) 를 생성할 때의 json 변환 규칙 재정의 하기 (null => “” 변환 등…)

By | 2월 11, 2022

일단 Spring 4에 내장된 jackson2 를 그대로 활용한다는 가정하에 기술한다. NullSerializer 작성 import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import java.io.IOException; /** * jackson > Object의 null값을 "null" 문자열 대신 ""로 출력할 수 있도록 설정 */ public class NullSerializer extends JsonSerializer<Object> { @Override public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException… Read More »

Spring 5 에 ehcache 2 적용 샘플

By | 4월 9, 2020

1.  pom.xml <dependency> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache</artifactId> <!– Spring 혹은 Terasoluna 에 최신버전이 내장되어 있어서 버전을 지정하지 않았었음. 아마 2.10.x 버전인듯 –> </dependency>   2. ehcache.xml <?xml version=”1.0″ encoding=”UTF-8″?> <ehcache xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”http://ehcache.org/ehcache.xsd” updateCheck=”false”> <!– * 속성 설명 (출처: https://javacan.tistory.com/entry/133) – maxElementsInMemory: 메모리에 저장될 수 있는 객체의 최대 개수 (필수) – eternal: 이 값이 true이면 timeout 관련 설정은… Read More »

Spring 파일 다운로드(file download)시 사용하는 View 샘플 코드

By | 9월 5, 2019

* View 정의 /** * 파일 다운로드시 Controller 에서 return 할 목적으로 생성한 view * * @author STEVE */ @Slf4j @Component(“fileDownloadView”) public class FileDownloadView extends AbstractView { private FileInputStream fin = null; private BufferedInputStream bis = null; private ServletOutputStream sout = null; private BufferedOutputStream bos = null; @SuppressWarnings(“rawtypes”) @Override protected void renderMergedOutputModel(Map params, HttpServletRequest request,… Read More »