Spring中HttpInvoker实例

阅读更多

Spring版本2.5.6.SEC01

1.服务端:

需要如下jar包:spring.jar spring-webmvc.jar

IPersonService.java

public interface IPersonService { public String queryPersonName(); }

PersonServiceImpl.java

public class PersonServiceImpl implements IPersonService { public String queryPersonName() { return "test"; } }

service-config.xml

serviceExporter

web.xml添加如下代码

dispatcherServlet org.springframework.web.servlet.DispatcherServlet contextConfigLocation /WEB-INF/service-config.xml 1 dispatcherServlet *.service

2.客户端:

客户端需要应用服务端的bean和接口,另外需要spring.jar

HttpInvokerClient.java

public class HttpInvokerClient { public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("httpinvoker-client.xml"); IPersonService service = (IPersonService) context.getBean("personServiceProxy"); String result = service.queryPerson(); System.out.println(result); } }

httpinvoker-client.xml

注意:ProjectContextRoot对应.mymetadata中的context-root,如果修改,需要重新启动Eclipse

你可能感兴趣的:(Spring,Bean,Servlet,XML,Web)