Category Archives: FrameWork

[spring] 파일 다운로드 컨트롤러 샘플 (file download, ResponseEntity)

By | 1월 5, 2024

환경 spring 4.3.25 import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import java.nio.file.Files; … @Controller public class FileController { @GetMapping("/download") public ResponseEntity<byte[]> download(HttpServletRequest request, Model model){ // TODO: 필요할 경우 여기에 권한 검증 로직 추가 // 아래의 값들은 DB조회 등을 통해 가져온다고 가정 String fileFullPath = "blabla~"; // file physical full path String oriFileName =… Read More »

[spring/mybatis] 오라클(oracle) 프로시저(procedure) 파라미터가 배열(array)일 경우 mybatis typehandler 예제

By | 12월 28, 2023

oracle type object CREATE OR REPLACE TYPE 스키마."VARR" IS TABLE OF VARCHAR2(2048); TypeHandler import oracle.jdbc.Oracleconnection; import org.apache.ibatis.type.BaseTypeHandler; import org.apache.ibatis.type.JdbcType public class VarrTypeHandler extends BaseTypeHandler<Object> { /** * DB에서 관리중인 Type의 이름 * – DB에 이 이름으로 Type Object가 미리 준비되어 있어야 함. */ private static final String TYPE_NAME = "VARR"; /** * 최초 구현하지 않았던… Read More »

[spring] jsp > jstl 에서 spring bean 에 접근하는 방법

By | 12월 19, 2023

테스트 환경 spring 4 포인트 jsp에서 접근하고자 하는 spring bean을 view resolver 에서 expose 해 준다. 샘플 코드 (spring) dispatcher-servlet.xml > InternalResourceViewResolver, TilesViewResolver 등에서 아래와 같은 형식으로 property를 set 해 준다. <property name="exposedContextBeanNames"> <list> <value>[jsp에서 접근하기 원하는 bean name]</value> </list> </property> 샘플 코드 (jsp) <c:set var="[변수명]" value="${[bean name]}" scope="application" /> 소감 application scope에 데이터를 셋팅하기… Read More »

[spring] 프로퍼티 파일 (*.properties) 의 내용을 정적 멤버(static member field)에 할당하는 방법 (feat. @Value)

By | 12월 5, 2023

방법 1 @Value 를 field가 아닌 static setter method 에 붙이기. => component 초기화 시 자동으로 setter가 호출된다고 한다. @Component public class MyBean { private static String staticProperty; @Value("${my.property}") private void setStaticProperty(String myProperty) { MyBean.staticProperty = myProperty; } public static String getStaticProperty() { return staticProperty; } } 소감 null fallback을 따로 해 주지 않아도 되서… Read More »

Spring 4 에서, controller method argument 로 HttpServletResponse를 추가했을 때, ContentNegotiatingViewResolver 를 통한 json view로의 resolving이 실행되지 않았던 건에 대하여

By | 10월 16, 2023

쓰고 보니 무슨 라노벨 제목처럼 되어 버렸네; 아무튼, 당연히 되어야 하는 json view response가 되지 않아서 한참을 삽질하다가 원인을 파악했다. (response가 argument에 있으면 안됨) 만약 특정 업무에서 response를 반드시 가공해야만 하는 경우가 생긴다면, 이미 만들어 둔 custom json view 에 분기코드를 심는 것이 좋을 것 같다. (controller 에서 model.addAttribute를 통해 분기 플래그 셋팅하는 등) gpt의… Read More »

[spring] WebMvcConfigurer > addInterceptors > excludePathPatterns 의 wildcard(*, asterisk) 문법에 대하여 (url 패턴에 의한 권한체크 필터)

By | 4월 27, 2023

예시 // 작동함 .excludePathPatterns("/aaa/**") .excludePathPatterns("/bbb*/**") // 작동하지 않음 .excludePathPatterns("/aaa**") // 별표 두개는 꼭 슬래쉬 뒤에 와야 하는 것 같다. 순서에 대하여 gpt에 물어보니, 패턴을 정의하는 순서에 의미가 있다고 한다. (위의 것이 먼저 필터링) 실험 결과 넓은 url 범위를 exclude 하고, 하위의 좁은 범위를 다시 add 했을 때, add가 의도한대록 작동(권한체크)되지는 않았다. (gpt는 된다고 했는데…?)

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

[링크] mybatis 에서 package 단위의 typealias를 정의할 때 wildcard (*) 사용하기

By | 7월 15, 2022

요약 아래의 형태 가능 (since mybatis-spring 2.0.1) mybatis.type-aliases-package=com.example.**.model mybatis.type-handlers-package=com.example.*.typehandler mybatis-config.xml 에서는 지원하지 않음 그냥 mybatis 가 아니라 mybatis-spring에서 지원하는 기능이기 때문 원글 https://github.com/mybatis/spring-boot-starter/issues/314

[펌글] 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 »

[ibatis/oracle] 내장 반복문을 통해 대량(배치, batch) insert 를 하는 샘플

By | 10월 21, 2021

Mybatis 아니고, 골동품인 Ibatis 입니다. 생각지도 못한 에러들이 나와서 (ora-00933 등..) 삽질을 했네요. (시간 아깝 ㅠ.ㅡ) <insert id="BatchDAO.insertMemberRest" parameterClass="java.util.HashMap"> INSERT ALL /* BatchDAO.insertMemberRest */ <iterate property="mberList" conjunction=" "> INTO COMTNGNRLMBERREST ( MBER_ID, PASSWORD ) VALUES ( #mberList[].MBER_ID#, #mberList[].PASSWORD# ) </iterate> SELECT * FROM DUAL </insert> 그런데 하다 보니 이것도 조심해야 할 것 같다는 생각이 들었다.… 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

Mybatis 오라클 프로시저 (Oracle Stored Procedure) 호출시, ‘java.sql.SQLException: 해당 위치에 지원되지 않는 SQL92 토큰: 1:’ 오류 발생 케이스.

By | 8월 20, 2021

이 케이스는 그야말로 황당 그 자체! 결론부터 말하면 mybatis xml 에서, 중괄호와 소괄호를 다른 라인에 위치시켜서 발생 한 문제이다. 그것도 같은 프레임워크에서 돌리는 MariaDB 프로시저 호출시는 문제가 없는데, ‘오라클 프로시저 호출시에만’ 이 문제가 발생했다. 전혀 예상 못하고 헤멜뻔 했는데, 인터넷에 또 선구자가 계셔서 해결할 수 있었다. 잘못된 예 { CALL PKG_A.PROC_TEST( #{rsltcode, mode=OUT, jdbcType=VARCHAR}, #{rsltmsg,… Read More »

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 »