- 浏览: 400243 次
- 性别:
- 来自: 安平人@北京
博客专栏
-
Netty学习笔记
浏览量:72746
文章分类
最新评论
-
sunnyhappylg:
问题:一个已经在线的redis集群 如何进行升级,需要把整个集 ...
Redis Cluster的FailOver失败案例分析 -
whmwg:
...
jdbctemplate与事务管理 -
facebook1314:
请问后台的HessianService能发布成多线程模式么(p ...
spring使用注解暴露remoting服务 -
wangyujie0431:
zhouwm402 写道我也是:service里面的dao没法 ...
spring使用注解暴露remoting服务 -
lcwen_13:
Scanner貌似是重复造轮子的赶脚
spring使用注解暴露remoting服务
spring使用注解暴露remoting服务
spring提供了多种序列化方式的基于http协议的rometing服务并且在使用的接口方式,服务端使用Exporter,客户端使用FactoryBean,例如hessian的HessianExporter和HessianProxyFactoryBean。exporter有两个参数比较关键一个是serviceInterface,另外一个是service bean本身。无论是HessianExporter还是HttpInvokerExporter都需要配置这两参数,目前spring是在配置文件中进行配置:
<bean id="helloService" class="lavasoft.suths.service.HelloService"/>
<bean name="/hello" class="org.springframework.remoting.caucho.HessianServiceExporter">
<property name="service" ref="helloService"/>
<property name="serviceInterface" value="lavasoft.suths.service.Hello"/>
</bean>
很显然有时候配置总是烦人,并且容易出错,有没有更简单的方式,通过注解的方式来暴露服务。如用注解又该来如何做呢?我们知道spring先生成beandefinition,再初始化bean。这样我们先扫描带有注解的service并根据该service构造exporter的bean definition并且注册。还是看看代码吧
for (String basePackage : basePackages) { Set<BeanDefinition> candidates = findCandidateComponents(basePackage); for (BeanDefinition candidate : candidates) { ScopeMetadata scopeMetadata = this.scopeMetadataResolver .resolveScopeMetadata(candidate); candidate.setScope(scopeMetadata.getScopeName()); String originalBeanName = this.beanNameGenerator.generateBeanName(candidate, this.registry); // if (candidate instanceof AbstractBeanDefinition) { // postProcessBeanDefinition((AbstractBeanDefinition) // candidate, originalBeanName); // } ScannedGenericBeanDefinition bd = (ScannedGenericBeanDefinition) candidate; String beanClassName = bd.getBeanClassName(); bd.setBeanClassName(JsonRpcExporter.class.getName()); bd.setBeanClass(JsonRpcExporter.class);//如果你用的hessian或者httpinvoker请换成相应的exporter bd.getPropertyValues().add("service", applicationContext.getBean(originalBeanName)); bd.getPropertyValues().add("beanClassName", beanClassName); String[] interfaces = bd.getMetadata().getInterfaceNames(); if (interfaces == null || interfaces.length == 0) continue; // HessianServiceExporter.class.getClassLoader().getResource(name) Class interf = null;
@Override protected void registerDefaultFilters() { addIncludeFilter(new AnnotationTypeFilter(JsonRpc.class));//只扫描带有JsonRpc的注解 }
@Component("helloService")
@JsonRpc("helloService") public class HelloServiceImpl implements IHelloService {
<bean id="scanner" class="com.taofang.scanner.HessianServiceScanner">
更新
非常感谢yangpeihai 兄的关注。起因是这样,我看到yang兄在一个帖子上说道能不能用注解暴露服务,正好这阶段我这也在做这方面的事情包括json-rpc,一看到这个帖子我就急匆匆的发了这篇blog,代码这也是从jsonrpc中摘出来的。也存在一些bug,要不是yang兄说他那边调试有问题,我现在还不知道。我发的这个版本,我把exporter的beanName和它引用的service的beanname搞混了,恰巧的是我把两个名字设成一样的,这个bug才隐藏在这里。按yang兄的要求我整了一份hessian的完整。测试类在test包中的ResourceTest。
bd.getPropertyValues().add("service", applicationContext.getBean(originalBeanName));//这里应该是exporter的service的beanname,
BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(candidate, "/" + beanName );//这里才是exporter的beanname,也是请求的url中的name
<property name="basePackage" value="com.taofang.service"></property> </bean
- scanner.rar (2.2 KB)
- 下载次数: 364
- hessianweb.rar (13.4 KB)
- 下载次数: 374
评论
service 中应该饮用RuntimeReference 而不是直接用applicationContext.getBean,因为getBean时resource没有注入
楼主能不能上传一个完整的helloWord例子(jar包除外),让我跟楼主helloWord ^_^,我 是 菜 鸟,别喷哈.....
非常感谢
那个是用来导出json-rpc服务。如果你用的是httpinvoker,
请将
bd.setBeanClass(JsonRpcExporter.class);//如果你用的hessian或者httpinvoker请换成相应的exporter
换成bd.setBeanClass(HttpInvokerServiceExporter.class);
并且创建一个类似JsonRpc的注解例如httpinvoker,同时修改
addIncludeFilter(new AnnotationTypeFilter(JsonRpc.class));//只扫描带有JsonRpc的注解
我会重构一下这个类,让通过配置参数扫描响应的服务。
我已经换为bd.setBeanClass(HttpInvokerServiceExporter.class)了,然后在我在service加上@JsonRpc,如下
@Service @JsonRpc("userServiceRemote") public class UserService implements IUserService { /** * */ private static final long serialVersionUID = -1863135765563158207L; @Autowired private UserDAO userDao; public List findAll() { return userDao.findAll(); } }
测试类如下:
public class UserServiceTest { private static IUserService userService = null; @BeforeClass public static void setUpBeforeClass() throws Exception { try { AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext-common.xml"); userService = (IUserService) ctx.getBean("userServiceRemote"); } catch (Exception e) { e.printStackTrace(); } } @Test public void testFindAll() { List<User> users = userService.findAll(); for (User user : users) { System.out.println(user); } } }
但是获取不到userServiceRemote对象哦,但是我可以获取到userService对象,请楼主指导下,我是否还要配置什么,我已经在applicationContext-common.xml配置了spring的annotation扫描
<context:annotation-config />
<context:component-scan base-package="com.oy" />
非常感谢
仁兄,是这样的。象remoting这样的服务,是通过beannameurlhandlermapping来分发的,所以该bean的name必须以"/"开头,就像咱们在xml配置的一样加上一个/,你试试userService = (IUserService) ctx.getBean("/userServiceRemote");或者加我qq405919612
非常感谢楼主耐心的回答,今晚回去加你QQ。
我刚才检查了一下,是我没有加上配置
<bean id="scanner" class="com.scanner.JsonRpcServiceScanner">
<property name="basePackage" value="com.oy.service"></property>
</bean>
service也做了修改
@Service("userService")
@JsonRpc("userService")
public class UserService implements IUserService
现在遇到另外一个错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name '/userService' defined in file [D:\myResource\ibatis\springMVC-ibatis\WebRoot\WEB-INF\classes\com\oy\service\UserService.class]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'beanClassName' of bean class [org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter]: Bean property 'beanClassName' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
我是哪里设置错了吗?
多谢 。。。。
非常抱歉,我自己写的JsonRpcExporter有classbeanName这个属性
bd.getPropertyValues().add("beanClassName", beanClassName);
你把这行去掉就可以了
实在是抱歉!整得比较仓促
举步维艰啊,好不容易初始化不报错,现在碰到两个问题:
1.单元测试时,service里面的dao没法被spring自动注入,如下:
@Autowired private UserDAO userDao;
2.部署到服务器后,没法访问暴露的service
服务端web.xml配置如下:
<servlet> <servlet-name>remote</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- 配置该Servlet随应用启动时候启动 --> <load-on-startup>1</load-on-startup> </servlet> <!-- 配置DispatcherServlet映射的url --> <servlet-mapping> <servlet-name>remote</servlet-name> <url-pattern>/remoting/*</url-pattern> </servlet-mapping>
客户端:
public static void main(String[] args) { ApplicationContext ctx = new FileSystemXmlApplicationContext("WebContent/WEB-INF/remote.xml"); BaseRemotingServiceFactory service = (BaseRemotingServiceFactory) ctx.getBean("baseRemoteService"); IUserService remoteService = (IUserService) service.getRemoteObject(IUserService.class, "http://127.0.0.1:7002/WebRoot", "userService"); List result = remoteService.findAll(); System.out.println(result); }
说明:在服务端使用annotation暴露远程服务前(以前是用xml配置暴露远程服务),我的客户端是可以访问的,所以排除客户端有问题。
楼主要是有时间,麻烦整一个完整的服务端例子,帮忙我们这些后来者一把,非常感谢
感谢关注,我提供了一个hessian的完整版本,你参考一下
cool~ 终于跑起来拉,楼主好人
楼主能不能上传一个完整的helloWord例子(jar包除外),让我跟楼主helloWord ^_^,我 是 菜 鸟,别喷哈.....
非常感谢
那个是用来导出json-rpc服务。如果你用的是httpinvoker,
请将
bd.setBeanClass(JsonRpcExporter.class);//如果你用的hessian或者httpinvoker请换成相应的exporter
换成bd.setBeanClass(HttpInvokerServiceExporter.class);
并且创建一个类似JsonRpc的注解例如httpinvoker,同时修改
addIncludeFilter(new AnnotationTypeFilter(JsonRpc.class));//只扫描带有JsonRpc的注解
我会重构一下这个类,让通过配置参数扫描响应的服务。
我已经换为bd.setBeanClass(HttpInvokerServiceExporter.class)了,然后在我在service加上@JsonRpc,如下
@Service @JsonRpc("userServiceRemote") public class UserService implements IUserService { /** * */ private static final long serialVersionUID = -1863135765563158207L; @Autowired private UserDAO userDao; public List findAll() { return userDao.findAll(); } }
测试类如下:
public class UserServiceTest { private static IUserService userService = null; @BeforeClass public static void setUpBeforeClass() throws Exception { try { AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext-common.xml"); userService = (IUserService) ctx.getBean("userServiceRemote"); } catch (Exception e) { e.printStackTrace(); } } @Test public void testFindAll() { List<User> users = userService.findAll(); for (User user : users) { System.out.println(user); } } }
但是获取不到userServiceRemote对象哦,但是我可以获取到userService对象,请楼主指导下,我是否还要配置什么,我已经在applicationContext-common.xml配置了spring的annotation扫描
<context:annotation-config />
<context:component-scan base-package="com.oy" />
非常感谢
仁兄,是这样的。象remoting这样的服务,是通过beannameurlhandlermapping来分发的,所以该bean的name必须以"/"开头,就像咱们在xml配置的一样加上一个/,你试试userService = (IUserService) ctx.getBean("/userServiceRemote");或者加我qq405919612
非常感谢楼主耐心的回答,今晚回去加你QQ。
我刚才检查了一下,是我没有加上配置
<bean id="scanner" class="com.scanner.JsonRpcServiceScanner">
<property name="basePackage" value="com.oy.service"></property>
</bean>
service也做了修改
@Service("userService")
@JsonRpc("userService")
public class UserService implements IUserService
现在遇到另外一个错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name '/userService' defined in file [D:\myResource\ibatis\springMVC-ibatis\WebRoot\WEB-INF\classes\com\oy\service\UserService.class]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'beanClassName' of bean class [org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter]: Bean property 'beanClassName' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
我是哪里设置错了吗?
多谢 。。。。
非常抱歉,我自己写的JsonRpcExporter有classbeanName这个属性
bd.getPropertyValues().add("beanClassName", beanClassName);
你把这行去掉就可以了
实在是抱歉!整得比较仓促
举步维艰啊,好不容易初始化不报错,现在碰到两个问题:
1.单元测试时,service里面的dao没法被spring自动注入,如下:
@Autowired private UserDAO userDao;
2.部署到服务器后,没法访问暴露的service
服务端web.xml配置如下:
<servlet> <servlet-name>remote</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- 配置该Servlet随应用启动时候启动 --> <load-on-startup>1</load-on-startup> </servlet> <!-- 配置DispatcherServlet映射的url --> <servlet-mapping> <servlet-name>remote</servlet-name> <url-pattern>/remoting/*</url-pattern> </servlet-mapping>
客户端:
public static void main(String[] args) { ApplicationContext ctx = new FileSystemXmlApplicationContext("WebContent/WEB-INF/remote.xml"); BaseRemotingServiceFactory service = (BaseRemotingServiceFactory) ctx.getBean("baseRemoteService"); IUserService remoteService = (IUserService) service.getRemoteObject(IUserService.class, "http://127.0.0.1:7002/WebRoot", "userService"); List result = remoteService.findAll(); System.out.println(result); }
说明:在服务端使用annotation暴露远程服务前(以前是用xml配置暴露远程服务),我的客户端是可以访问的,所以排除客户端有问题。
楼主要是有时间,麻烦整一个完整的服务端例子,帮忙我们这些后来者一把,非常感谢
感谢关注,我提供了一个hessian的完整版本,你参考一下
楼主能不能上传一个完整的helloWord例子(jar包除外),让我跟楼主helloWord ^_^,我 是 菜 鸟,别喷哈.....
非常感谢
那个是用来导出json-rpc服务。如果你用的是httpinvoker,
请将
bd.setBeanClass(JsonRpcExporter.class);//如果你用的hessian或者httpinvoker请换成相应的exporter
换成bd.setBeanClass(HttpInvokerServiceExporter.class);
并且创建一个类似JsonRpc的注解例如httpinvoker,同时修改
addIncludeFilter(new AnnotationTypeFilter(JsonRpc.class));//只扫描带有JsonRpc的注解
我会重构一下这个类,让通过配置参数扫描响应的服务。
我已经换为bd.setBeanClass(HttpInvokerServiceExporter.class)了,然后在我在service加上@JsonRpc,如下
@Service @JsonRpc("userServiceRemote") public class UserService implements IUserService { /** * */ private static final long serialVersionUID = -1863135765563158207L; @Autowired private UserDAO userDao; public List findAll() { return userDao.findAll(); } }
测试类如下:
public class UserServiceTest { private static IUserService userService = null; @BeforeClass public static void setUpBeforeClass() throws Exception { try { AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext-common.xml"); userService = (IUserService) ctx.getBean("userServiceRemote"); } catch (Exception e) { e.printStackTrace(); } } @Test public void testFindAll() { List<User> users = userService.findAll(); for (User user : users) { System.out.println(user); } } }
但是获取不到userServiceRemote对象哦,但是我可以获取到userService对象,请楼主指导下,我是否还要配置什么,我已经在applicationContext-common.xml配置了spring的annotation扫描
<context:annotation-config />
<context:component-scan base-package="com.oy" />
非常感谢
仁兄,是这样的。象remoting这样的服务,是通过beannameurlhandlermapping来分发的,所以该bean的name必须以"/"开头,就像咱们在xml配置的一样加上一个/,你试试userService = (IUserService) ctx.getBean("/userServiceRemote");或者加我qq405919612
非常感谢楼主耐心的回答,今晚回去加你QQ。
我刚才检查了一下,是我没有加上配置
<bean id="scanner" class="com.scanner.JsonRpcServiceScanner">
<property name="basePackage" value="com.oy.service"></property>
</bean>
service也做了修改
@Service("userService")
@JsonRpc("userService")
public class UserService implements IUserService
现在遇到另外一个错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name '/userService' defined in file [D:\myResource\ibatis\springMVC-ibatis\WebRoot\WEB-INF\classes\com\oy\service\UserService.class]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'beanClassName' of bean class [org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter]: Bean property 'beanClassName' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
我是哪里设置错了吗?
多谢 。。。。
非常抱歉,我自己写的JsonRpcExporter有classbeanName这个属性
bd.getPropertyValues().add("beanClassName", beanClassName);
你把这行去掉就可以了
实在是抱歉!整得比较仓促
举步维艰啊,好不容易初始化不报错,现在碰到两个问题:
1.单元测试时,service里面的dao没法被spring自动注入,如下:
@Autowired private UserDAO userDao;
2.部署到服务器后,没法访问暴露的service
服务端web.xml配置如下:
<servlet> <servlet-name>remote</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- 配置该Servlet随应用启动时候启动 --> <load-on-startup>1</load-on-startup> </servlet> <!-- 配置DispatcherServlet映射的url --> <servlet-mapping> <servlet-name>remote</servlet-name> <url-pattern>/remoting/*</url-pattern> </servlet-mapping>
客户端:
public static void main(String[] args) { ApplicationContext ctx = new FileSystemXmlApplicationContext("WebContent/WEB-INF/remote.xml"); BaseRemotingServiceFactory service = (BaseRemotingServiceFactory) ctx.getBean("baseRemoteService"); IUserService remoteService = (IUserService) service.getRemoteObject(IUserService.class, "http://127.0.0.1:7002/WebRoot", "userService"); List result = remoteService.findAll(); System.out.println(result); }
说明:在服务端使用annotation暴露远程服务前(以前是用xml配置暴露远程服务),我的客户端是可以访问的,所以排除客户端有问题。
楼主要是有时间,麻烦整一个完整的服务端例子,帮忙我们这些后来者一把,非常感谢
楼主能不能上传一个完整的helloWord例子(jar包除外),让我跟楼主helloWord ^_^,我 是 菜 鸟,别喷哈.....
非常感谢
那个是用来导出json-rpc服务。如果你用的是httpinvoker,
请将
bd.setBeanClass(JsonRpcExporter.class);//如果你用的hessian或者httpinvoker请换成相应的exporter
换成bd.setBeanClass(HttpInvokerServiceExporter.class);
并且创建一个类似JsonRpc的注解例如httpinvoker,同时修改
addIncludeFilter(new AnnotationTypeFilter(JsonRpc.class));//只扫描带有JsonRpc的注解
我会重构一下这个类,让通过配置参数扫描响应的服务。
我已经换为bd.setBeanClass(HttpInvokerServiceExporter.class)了,然后在我在service加上@JsonRpc,如下
@Service @JsonRpc("userServiceRemote") public class UserService implements IUserService { /** * */ private static final long serialVersionUID = -1863135765563158207L; @Autowired private UserDAO userDao; public List findAll() { return userDao.findAll(); } }
测试类如下:
public class UserServiceTest { private static IUserService userService = null; @BeforeClass public static void setUpBeforeClass() throws Exception { try { AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext-common.xml"); userService = (IUserService) ctx.getBean("userServiceRemote"); } catch (Exception e) { e.printStackTrace(); } } @Test public void testFindAll() { List<User> users = userService.findAll(); for (User user : users) { System.out.println(user); } } }
但是获取不到userServiceRemote对象哦,但是我可以获取到userService对象,请楼主指导下,我是否还要配置什么,我已经在applicationContext-common.xml配置了spring的annotation扫描
<context:annotation-config />
<context:component-scan base-package="com.oy" />
非常感谢
仁兄,是这样的。象remoting这样的服务,是通过beannameurlhandlermapping来分发的,所以该bean的name必须以"/"开头,就像咱们在xml配置的一样加上一个/,你试试userService = (IUserService) ctx.getBean("/userServiceRemote");或者加我qq405919612
非常感谢楼主耐心的回答,今晚回去加你QQ。
我刚才检查了一下,是我没有加上配置
<bean id="scanner" class="com.scanner.JsonRpcServiceScanner">
<property name="basePackage" value="com.oy.service"></property>
</bean>
service也做了修改
@Service("userService")
@JsonRpc("userService")
public class UserService implements IUserService
现在遇到另外一个错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name '/userService' defined in file [D:\myResource\ibatis\springMVC-ibatis\WebRoot\WEB-INF\classes\com\oy\service\UserService.class]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'beanClassName' of bean class [org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter]: Bean property 'beanClassName' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
我是哪里设置错了吗?
多谢 。。。。
非常抱歉,我自己写的JsonRpcExporter有classbeanName这个属性
bd.getPropertyValues().add("beanClassName", beanClassName);
你把这行去掉就可以了
实在是抱歉!整得比较仓促
楼主能不能上传一个完整的helloWord例子(jar包除外),让我跟楼主helloWord ^_^,我 是 菜 鸟,别喷哈.....
非常感谢
那个是用来导出json-rpc服务。如果你用的是httpinvoker,
请将
bd.setBeanClass(JsonRpcExporter.class);//如果你用的hessian或者httpinvoker请换成相应的exporter
换成bd.setBeanClass(HttpInvokerServiceExporter.class);
并且创建一个类似JsonRpc的注解例如httpinvoker,同时修改
addIncludeFilter(new AnnotationTypeFilter(JsonRpc.class));//只扫描带有JsonRpc的注解
我会重构一下这个类,让通过配置参数扫描响应的服务。
我已经换为bd.setBeanClass(HttpInvokerServiceExporter.class)了,然后在我在service加上@JsonRpc,如下
@Service @JsonRpc("userServiceRemote") public class UserService implements IUserService { /** * */ private static final long serialVersionUID = -1863135765563158207L; @Autowired private UserDAO userDao; public List findAll() { return userDao.findAll(); } }
测试类如下:
public class UserServiceTest { private static IUserService userService = null; @BeforeClass public static void setUpBeforeClass() throws Exception { try { AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext-common.xml"); userService = (IUserService) ctx.getBean("userServiceRemote"); } catch (Exception e) { e.printStackTrace(); } } @Test public void testFindAll() { List<User> users = userService.findAll(); for (User user : users) { System.out.println(user); } } }
但是获取不到userServiceRemote对象哦,但是我可以获取到userService对象,请楼主指导下,我是否还要配置什么,我已经在applicationContext-common.xml配置了spring的annotation扫描
<context:annotation-config />
<context:component-scan base-package="com.oy" />
非常感谢
仁兄,是这样的。象remoting这样的服务,是通过beannameurlhandlermapping来分发的,所以该bean的name必须以"/"开头,就像咱们在xml配置的一样加上一个/,你试试userService = (IUserService) ctx.getBean("/userServiceRemote");或者加我qq405919612
非常感谢楼主耐心的回答,今晚回去加你QQ。
我刚才检查了一下,是我没有加上配置
<bean id="scanner" class="com.scanner.JsonRpcServiceScanner">
<property name="basePackage" value="com.oy.service"></property>
</bean>
service也做了修改
@Service("userService")
@JsonRpc("userService")
public class UserService implements IUserService
现在遇到另外一个错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name '/userService' defined in file [D:\myResource\ibatis\springMVC-ibatis\WebRoot\WEB-INF\classes\com\oy\service\UserService.class]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'beanClassName' of bean class [org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter]: Bean property 'beanClassName' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
我是哪里设置错了吗?
多谢 。。。。
楼主能不能上传一个完整的helloWord例子(jar包除外),让我跟楼主helloWord ^_^,我 是 菜 鸟,别喷哈.....
非常感谢
那个是用来导出json-rpc服务。如果你用的是httpinvoker,
请将
bd.setBeanClass(JsonRpcExporter.class);//如果你用的hessian或者httpinvoker请换成相应的exporter
换成bd.setBeanClass(HttpInvokerServiceExporter.class);
并且创建一个类似JsonRpc的注解例如httpinvoker,同时修改
addIncludeFilter(new AnnotationTypeFilter(JsonRpc.class));//只扫描带有JsonRpc的注解
我会重构一下这个类,让通过配置参数扫描响应的服务。
我已经换为bd.setBeanClass(HttpInvokerServiceExporter.class)了,然后在我在service加上@JsonRpc,如下
@Service @JsonRpc("userServiceRemote") public class UserService implements IUserService { /** * */ private static final long serialVersionUID = -1863135765563158207L; @Autowired private UserDAO userDao; public List findAll() { return userDao.findAll(); } }
测试类如下:
public class UserServiceTest { private static IUserService userService = null; @BeforeClass public static void setUpBeforeClass() throws Exception { try { AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext-common.xml"); userService = (IUserService) ctx.getBean("userServiceRemote"); } catch (Exception e) { e.printStackTrace(); } } @Test public void testFindAll() { List<User> users = userService.findAll(); for (User user : users) { System.out.println(user); } } }
但是获取不到userServiceRemote对象哦,但是我可以获取到userService对象,请楼主指导下,我是否还要配置什么,我已经在applicationContext-common.xml配置了spring的annotation扫描
<context:annotation-config />
<context:component-scan base-package="com.oy" />
非常感谢
仁兄,是这样的。象remoting这样的服务,是通过beannameurlhandlermapping来分发的,所以该bean的name必须以"/"开头,就像咱们在xml配置的一样加上一个/,你试试userService = (IUserService) ctx.getBean("/userServiceRemote");或者加我qq405919612
楼主能不能上传一个完整的helloWord例子(jar包除外),让我跟楼主helloWord ^_^,我 是 菜 鸟,别喷哈.....
非常感谢
那个是用来导出json-rpc服务。如果你用的是httpinvoker,
请将
bd.setBeanClass(JsonRpcExporter.class);//如果你用的hessian或者httpinvoker请换成相应的exporter
换成bd.setBeanClass(HttpInvokerServiceExporter.class);
并且创建一个类似JsonRpc的注解例如httpinvoker,同时修改
addIncludeFilter(new AnnotationTypeFilter(JsonRpc.class));//只扫描带有JsonRpc的注解
我会重构一下这个类,让通过配置参数扫描响应的服务。
我已经换为bd.setBeanClass(HttpInvokerServiceExporter.class)了,然后在我在service加上@JsonRpc,如下
@Service @JsonRpc("userServiceRemote") public class UserService implements IUserService { /** * */ private static final long serialVersionUID = -1863135765563158207L; @Autowired private UserDAO userDao; public List findAll() { return userDao.findAll(); } }
测试类如下:
public class UserServiceTest { private static IUserService userService = null; @BeforeClass public static void setUpBeforeClass() throws Exception { try { AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext-common.xml"); userService = (IUserService) ctx.getBean("userServiceRemote"); } catch (Exception e) { e.printStackTrace(); } } @Test public void testFindAll() { List<User> users = userService.findAll(); for (User user : users) { System.out.println(user); } } }
但是获取不到userServiceRemote对象哦,但是我可以获取到userService对象,请楼主指导下,我是否还要配置什么,我已经在applicationContext-common.xml配置了spring的annotation扫描
<context:annotation-config />
<context:component-scan base-package="com.oy" />
非常感谢
楼主能不能上传一个完整的helloWord例子(jar包除外),让我跟楼主helloWord ^_^,我 是 菜 鸟,别喷哈.....
非常感谢
那个是用来导出json-rpc服务。如果你用的是httpinvoker,
请将
bd.setBeanClass(JsonRpcExporter.class);//如果你用的hessian或者httpinvoker请换成相应的exporter
换成bd.setBeanClass(HttpInvokerServiceExporter.class);
并且创建一个类似JsonRpc的注解例如httpinvoker,同时修改
addIncludeFilter(new AnnotationTypeFilter(JsonRpc.class));//只扫描带有JsonRpc的注解
我会重构一下这个类,让通过配置参数扫描响应的服务。
@RpcExporter(protocol="json")
不错,可以把我封转的那个改进改进
楼主能不能上传一个完整的helloWord例子(jar包除外),让我跟楼主helloWord ^_^,我 是 菜 鸟,别喷哈.....
非常感谢
那个是用来导出json-rpc服务。如果你用的是httpinvoker,
请将
bd.setBeanClass(JsonRpcExporter.class);//如果你用的hessian或者httpinvoker请换成相应的exporter
换成bd.setBeanClass(HttpInvokerServiceExporter.class);
并且创建一个类似JsonRpc的注解例如httpinvoker,同时修改
addIncludeFilter(new AnnotationTypeFilter(JsonRpc.class));//只扫描带有JsonRpc的注解
我会重构一下这个类,让通过配置参数扫描响应的服务。
楼主能不能上传一个完整的helloWord例子(jar包除外),让我跟楼主helloWord ^_^,我 是 菜 鸟,别喷哈.....
非常感谢
相关推荐
使用Spring.Net IoC注入数据访问层, 发布为Remoting服务, 供Web层调用. 3, Web 实现UI, 组织数据提交WebService处理. 层与层之间是独立的. 声明: 本框架仅做为个人研究使用, 若有任何问题或因使用产生的任何损失...
常用的Remoting宿主往往是Console,Windows服务。而用IIS作为宿主的情况并不多。前一段时间思考分布式系统的缓存设计时,考虑到使用多个Web应用程序(甚至包括Console,WinForm程序)一起共享数据的实现,就想到了...
spring-remoting.jar spring-remoting.jar
项目工程结构如下图所示,除了包含spring定义远程服务org.springframework.remoting.httpinvoker.*部分节点代码(红框框部分,具体设计代码部分参考相关代码示例说明文章),还包含springmvc等其他示例部分可以忽略...
由于spring2和spring3的rmi方式调用方式不同引起的,通过查阅相关文档后发现,spring3不在需要生成skeleton和stub了,所以把这个类从spring-context中删除了,解决办法就是想办法将它再加进来
remoting应用程序,接口实现远程访问
使用.NET Remoting从服务器主动发出事件通知客户端(远程广播) 经常看见有人问:使用.NET Remoting如何从服务器主动发出事件通知客户端?的确,初接触.NET Remoting的人多半会有这样的疑问,因为大部分的文章和...
未完成程序. remoting服务自动转换为webservice服务 thanks
刘冬编写Spring.NET学习笔记20——整合Remoting(应用篇)的例子 原文:http://www.cnblogs.com/GoodHelper/archive/2009/11/19/SpringNet_Remoting.html
Remoting服务A与Remoting服务B相互通信,客户c可以直接访问服务A和B。服务之间的通讯与逻辑设计,是在各自的宿主程序上,进行,可以再宿主程序上开发相关逻辑,让两个服务找自己的逻辑交换数据。
NULL 博文链接:https://zcmerjade.iteye.com/blog/1476218
正是这些技巧,仿佛森严的壁垒,让许多人望而生畏,或者是不知所谓,最后放弃了事件在Remoting的使用。关于这个主题,在网上也有很多讨论,相关的技术文章也不少,遗憾的是,很多文章概述的都不太全面。我在研究...
org.apache.cxf.spring.remoting.Jsr181HandlerMapping.jar
org.springframework.remoting.caucho.BurlapClientInterceptor.class org.springframework.remoting.caucho.BurlapProxyFactoryBean.class org.springframework.remoting.caucho.BurlapServiceExporter.class org....
资源名称:使用.NET Remoting 建立分布式应用程序视频教程资源目录:【】7a541feba03b93376377e76e561c5c75【】f037c18f05fb8b08213aaf289f7e594c【】使用.NETRemoting建立分布式应用程序(一)【】使用.NETRemoting...
学web Service(web服务)和.net remoting必看的一本书 它绝对可以提高你的.net水平,收2分咯! 下完请下第二部分才能解压
使用Remoting开发分布式应用使用Remoting开发分布式应用