Framework

멀캠교육요약 4일차-Spring,Hibernate,ibatis

MorningPhys 2015. 7. 19. 20:18

** Struts와 Spring 같이 쓰기

- web단은 struts로 하고 business단은 spring으로 구현할 때 두가지 방법 있다.

- applicationContext.getBean()해서 쓰는 방법

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/com/multicampus/simplewiki/spring/applicationContext-wiki.xml</param-value>
</context-param>

 

Action에서 getBean하는 방법 생각 안남 소스는 나중에

 

- Struts Action을 SpringMVC처럼 bean injaction해 주는 방법

<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/user-service.xml,/WEB-INF/user-data.xml" />
</plug-in>

=> 이거 쓰면 web.xml에 <context-param> 에 spring에서 사용하는 xml 안써도 된다.

 

** 위 주제 관련하여 매우 유용한 포스트!!! 굿!

http://blog.naver.com/sckim0524?Redirect=Log&logNo=56079782

** Distribute Spring

- 기본적으로 Spring은 distribute 환경 지원하지 않는다.

- 대신 EJB, JNDI, RMI, WebService 등 Distribute 환경을 지원하는 Support 객체를 지원한다.

- EJB로 Distribute 구현할 때 EJB는 network proxy역할만 시킨다. 실제 business logic은 spring bean에 구현할 것을 권장

 

** WebService Server with Spring

- WebService로 공개할 ServiceImpl을 만든다. (interface 만드는 것은 생략)

public class WikiServiceImpl extends ServletEndpointSupport implements WikiService{

public DocumentVO findDocument(int documentId) {
DocumentService service = (DocumentService) getWebApplicationContext().getBean("documentService");
Document document = service.findDocument(documentId);

DocumentVO vo = new DocumentVO();

vo.setId(document.getId());
vo.setTitle(document.getTitle());
vo.setContent(document.getContent());

return vo;
}

}

 

 

- WebService로 만든다.

 

- WSDL 확인 

 

** Client 만들기

=> Client Project에서 New->Other... 선택

 

 

- wsdl 경로 지정 하고 finish 하면 wsdl에서 정의된 class들이 자동으로 생성된다.

 

 

- Client에서 실행해 볼 프로그램 예제 => WikiServiceImplProxy : 자동으로 생성된거다

public class Test {
public static void main(String[] args) {
try {
WikiServiceImplProxy proxy = new WikiServiceImplProxy();
DocumentVO vo = proxy.findDocument(3);
System.out.println(vo.getId() + ":" + vo.getTitle());
}
catch (Exception e) {
// TODO: handle exception
}
}
}

 

 

[출처] http://rarelhw.blog.me/110039250366

 

반응형