Category Archives: Spring

스프링(spring) 어플리케이션(application) 시작시 원하는 메서드가 실행되도록 하는 방법

By | 10월 25, 2011

1. ApplicationListener 구현 import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationListener; public class Test implements ApplicationListener{ //변수와 setter를 선언하여 bean xml 로부터 값을 넘겨받을 수 있다. String var1; public void setVar1(String var1) { this.var1 = var1; } //스프링 시스템 기동시 수행 public void onApplicationEvent(ApplicationEvent applicationevent) { System.out.println(“### Test.onApplicationEvent() > var1 : “+ var1 +”###”); } } * implements 할… Read More »

Spring에서 트랜젝션 내에 별도의 트랜젝션을 가져가는 방법 (Spring 2.5 / 어노테이션 기반 트랜젝션)

By | 6월 22, 2011

어노테이션 기반 트랜젝션 (예:<tx:annotation-driven/>) 에서 어떤 클래스에 @Transactional 이 선언되어 있고 이 클래스는 다음과 같은 메서드를 가진다고 할 때 메서드A(){          for(int i=0; i<10; i++){         메서드B();     }  } 메서드A()는 스프링의 프록시로 감싸져 있기 때문에 Exception 발생시 롤백이 가능하지만, 그 안에 있는 메서드B()는 현재 개별적인 트랜젝션처리(각 루프별 독립적 롤백)가 불가능한 상태이다. 이 경우에는 다음과 같이… Read More »

[펌글] STRUTS – SPRING 연계 방법

By | 8월 21, 2009

[출처] STRUTS – SPRING 연계|작성자 돌맹이 1. 코드로 서비스를 직접 받아 오기 아주 단순한 방법이다. ApplicationContext를 가져 와서 bean을 직접 찾아 온다. 스트럿츠의 action에서 직접 코딩해 준다. 1) Action 클래스는 org.springframework.web.struts.ActionSupport 를 상속해야 한다. 2) 직접 코딩      ApplicationContext ctx = getWebApplicationContext();      TreeService treeService = (TreeService)ctx.getBean(“treeService”); 특징: 스프링과 스트럿츠가 완전 따로 논다. 장점: 설정이… Read More »

valang 에서 정규표현식(regex) 사용하는 예제

By | 3월 14, 2009

<bean id=”theValidator” class=”org.springmodules.validation.valang.ValangValidator”>   <property name=”valang”>      <value>       <![CDATA[        { numfield : ? NOT NULL and matches(‘정규식’,?) is true : ‘numfield  no match’ : ‘numfield.nomatch’ }       ]]>     </value>   </property> </bean> 이거 알아내느라고 힘들었다능.. ㅠ_ㅠ.. matches 말고 match도 쓰는 것 같은데 차이를 모르겠다… – 출처 : 구글에게구걸 –

Spring Tag의 FORM 관련 객체 사용법 HTML Tag와의 비교

By | 1월 30, 2009

* form 객체 이름   HTML – <form name=”이름”/>   Spring – <form:form commandName=”이름”/>                     => commandName은 HTML렌더링 후 id가 되므로 getElementById()를 사용해서 참조할 수 있다. * input 객체 이름   HTML – <input name=”이름”/>   Spring – <form:input path=”이름”/>               => HTML의 input 태그도 <form:form> 태그 안에 있으면 input의 name이 커맨드객체의 멤버변수로                    맵핑 가능하다.   * CSS 스타일 적용… Read More »