1 实体,必须序列化
public class UcServiceEntity implements Serializable{ /** * @Fields serialVersionUID : TODO */ private static final long serialVersionUID = 1L; private String name; private String age ; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAge() { return age; } public void setAge(String age) { this.age = age; } }
2 服务端与客户端的接口
package com.mainbo.u3.service; import java.util.Map; public interface UcService { public String getUserInfobyName(String userName); public int recordLog(String username, String point, String operate, String desc); public Map getUserInfobyName(Map userMap); public UcServiceEntity getUserInfobyName(UcServiceEntity entity); }
3 服务端接口实现
@Service("ucService") public class UCServiceImpl implements UcService { private static Logger pointrecordlog = Logger.getLogger("pointrecordlog"); private static Logger logger = Logger.getLogger(UCServiceImpl.class); public String getUserInfobyName(String userName) { return userName+"12" ; } public int recordLog(String username, String point, String operate, String desc) { int result = 0; try { pointrecordlog.info(username + " - " + point + " - " + operate + " - " + desc); } catch (Throwable t) { result = -1; logger.error(t); } return result; } @Override public Map getUserInfobyName(Map userMap) { System.out.println( userMap); Map map = new HashMap(); map.put("userName", "王战涛"); return map; } @Override public UcServiceEntity getUserInfobyName(UcServiceEntity entity) { System.out.println( entity.getName()); entity.setName("getUserInfobyName"); return entity; } }
4 映射mapping ,在springmvc 的配置文件中*-servlet.xml中
<bean class="org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter"/> <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <prop key="/httpService">httpService</prop> </props> </property> </bean>
5 ApplicationContext.xml中配置HttpInvoker
<bean id="httpService" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter"> <property name="service"> <ref bean="ucService" /> </property> <property name="serviceInterface" value=" com.mainbo.u3.service.UcService"> </property> </bean>
6 web.xml中暴漏接口
<servlet> <servlet-name>u3</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>3</load-on-startup> </servlet> <servlet-mapping> <servlet-name>u3</servlet-name> <url-pattern>/service/*</url-pattern> </servlet-mapping>
7 客户端配置ApplicationContext.xml ,暴漏访问url
<bean id="httpService" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean"> <property name="serviceUrl" value="http://localhost:80/service/httpService" /> <property name="serviceInterface" value=" com.mainbo.u3.service.UcService" /> </bean>
8 主函数进行测试
public static void main(String[] args) { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( new String[] {"u3-core.xml" }); UcService us = (UcService)ctx.getBean("httpService"); String userName = us.getUserInfobyName("111111"); System.out.println( userName ); Map map = new HashMap(); map.put("userName", "王涛1"); Map mapUser = us.getUserInfobyName(map ); System.out.println(mapUser.get("userName") ); UcServiceEntity entity = new UcServiceEntity(); entity.setName("传递实体"); UcServiceEntity entity2 = us.getUserInfobyName(entity); System.out.println(entity2 ); }
相关推荐
NULL 博文链接:https://snowolf.iteye.com/blog/703732
springboot 使用spring cache缓存 和 使用fastjson配置redis系列化,springboot 使用spring cache缓存 和 使用fastjson配置redis系列化,springboot 使用spring cache缓存 和 使用fastjson配置redis系列化,springboot ...
Spring 标签 使用指南 Spring 标签 使用指南 Spring 标签 使用指南
通过对SRPING aop的使用和研究,总结出来的SPRING AOP使用原理,以及在使用spring aop过程中要注意的问题
在Spring中使用JTA事务管理 1 通过集成JOTM,直接在Spring中使用JTA事务 1.1. 将JOTM以下类库添加到类路径中 1.2. 编写JOTM配置文件,放到类路径下 1.3. 在MySQL上建立两个数据库 1.4. 在Spring配置文件中配置JOTM ...
Spring Aop的使用实例
SpringPython使用介绍指南.doc
一般使用mybatis的环境,大多都是别人已经配置...我文章中的方法不基于spring,一般很少会在真实项目中直接使用。我把我的搭建过程记录下来给有用的人吧。 https://blog.csdn.net/lxyoucan/article/details/126162493
spring security 使用及配置
在spring中使用Hibernate是平时项目中很常用的做法,下面就具体步骤进行
使用Spring的注解方式实现AOP的细节
以上资料是使用spring mvc参考资料
spring boot使用了默认大于配置的理念,很多集成方案已经帮你选择好了,能不配置就不配置,Spring Cloud很大的一部分是基于Spring boot来实现。Spring boot可以离开Spring Cloud独立使用开发项目,但是Spring Cloud...
Spring Boot使用spring-data-jpa配置Mysql多数据源,可用版本
springsecurity使用demo
spring roo 官方文档。很权威的东西。最新版本1.1.5的。
SPRING定时器使用说明
Spring基础:Spring AOP简单使用
Spring Batch是一个轻量级的,完全面向Spring的批处理框架,可以应用于企业级大量的数据处理系统。Spring Batch以POJO和大家熟知的Spring框架为基础,使开发者更容易的访问和利用企业级服务。Spring Batch可以提供...
spring使用web socket,spring使用web socket,spring使用web socket