Category Archives: Spring

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 »

[펌글] Spring MVC 사용시 Controller Method 없이 View Jsp를 매핑해 주도록 하는 설정 (mvc:view-controller)

By | 2월 28, 2017

– 출처: http://kdarkdev.tistory.com/105 –   별도의 모델이나 컨트롤러가 없이 URL요청이 왔을때 뷰로 연결만 해주는 경우는 굳이 컨트롤러가 필요없이 <mvc:view-controller>태그를 사용하면 URL과  뷰를 매핑해 줄 수 있습니다. 아래의 태그는 /common/gg 라는 URL을  요청 받았을때 gg라는 뷰 이름을 리턴 받게 됩니다 만약 InternalResourceViewResolver 에서 prefix/suffix가 각각 /WEB-INF/jsp/ 와 .jsp 라고 가정 한다면 결과적으로 /WEB-INF/jsp/gg.jsp 라는 jsp view를 찾게 됩니다.   <mvc:view-controller path=”/common/gg”… Read More »

java 프로퍼티 파일 읽기 예시 (java.util.Properties, org.springframework.util.ResourceUtils)

By | 11월 25, 2015

  Properties props = new Properties(); try{ props.load(new FileInputStream(ResourceUtils.getFile(“classpath:config/properties/test.properties”))) //classpath 기준으로 찾을 경우 //props.load(new FileInputStream(ResourceUtils.getFile(“file:C:/project/src/main/resources/config/properties/test.properties”))) //파일시스템 기준으로 찾을 경우 }catch(IOException e){ e.printStackTrace(); } String testValue = props.get(“testKey”);     * 이러한 류의 작업은 File I/O를 사용하기 때문에 시스템 기동부나 테스트코드에서 사용해야지, 자주 반복되는 구간에서 사용해서는 안된다.    

Spring 3 에서 컨트롤러 메서드(Controller Method) 진입시 어노테이션(Annotation)을 활용한 인터셉터(Interceptor) 만들기

By | 10월 29, 2014

  1. 어노테이션 인터페이스 작성 @Retention(RetentionPolicy.RUNTIME) @Target(value = {ElementType.TYPE, ElementType.METHOD}) //클래스 혹은 메서드에 어노테이션 적용 public @interface SslCheck { boolean isBlock() default false; //어노테이션에 인수를 입력받아 활용하고 싶을 경우 메서드 정의 }     2. HandlerInterceptorAdapter를 상속받은 인터셉터 클래스를 작성하면서 어노테이션을 활용 public class SslCheckInterceptor extends HandlerInterceptorAdapter { //주로 preHandle()에 로직을 작성할 것이다. @Override public… Read More »

Spring 3 에서 response.sendRedirect()를 사용하여 SSL(https) 요청을 생성할 때 https가 되지 않고 http로 되는 문제에 대한 해결 방안

By | 10월 29, 2014

만약 ViewResolver로서 UrlBasedViewResolver를 상속받은 ViewResolver를 사용하고 있다면, ViewResolver의 xml 정의에 아래와 같이 redirectHttp10Compatible 멤버를 false로 셋팅해 주면 된다.   <bean class=”org.springframework.web.servlet.view.UrlBasedViewResolver” id=”tilesViewResolver”> <property name=”viewClass” value=”org.springframework.web.servlet.view.tiles3.TilesView” /> <property name=”redirectHttp10Compatible” value=”false” /> </bean>                  

Spring 3.1 이 java 객체를 json으로 변환해 줄 때, 값이 없는 객체는 json에 빈문자("") 대신 "null" 문자열을 리턴해 주는데, 이를 빈문자("")로 리턴해 주도록 바꾸는 방법

By | 8월 5, 2014

– 출처 :  http://stackoverflow.com/questions/12934045/null-values-as-empty-strings-when-using-responsebody-annotation –   1. null serializer 를 작성한다. import java.io.IOException; import org.codehaus.jackson.JsonGenerator; import org.codehaus.jackson.JsonProcessingException; import org.codehaus.jackson.map.JsonSerializer; import org.codehaus.jackson.map.SerializerProvider; public class NullSerializer extends JsonSerializer<Object> { @Override public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeString(“”); } }     2. custom object mapper 를 작성한다.  (위에서 작성한 NullSerializer 사용) import… Read More »

[펌글] 스프링의 StringUtils 메서드 정리

By | 1월 20, 2012

– 출처 : http://julingks.tistory.com/38 – 스프링에서 StringUtils 살펴보기 Util 라이브러리를 120% 활용하기 위해서는 어떤 메소드를 제공하는가를 빨리 파악해야 한다. 그래야 불필요 없는 중복 코드를 생성하지 않고, 자주 쓰는 간단한 함수를 작성하는데 드는 시간을 절약할 수 있다. org.springframework.util 패키지에 있는 StringUtils 클래스를 살펴보자. API 문서 http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/util/StringUtils.html 스트링 관련 잡단한 메서드들이 있다. 스프링 프레임웍 내부에서 사용하기 위해서 만들었는 데 Jakarta’s Commons Lang의 스트링 유틸리티들의… Read More »