- 浏览: 406767 次
- 性别:
- 来自: 安平人@北京
-
博客专栏
-
-
Netty学习笔记
浏览量:73383
文章分类
最新评论
-
sunnyhappylg:
问题:一个已经在线的redis集群 如何进行升级,需要把整个集 ...
Redis Cluster的FailOver失败案例分析 -
whmwg:
...
jdbctemplate与事务管理 -
facebook1314:
请问后台的HessianService能发布成多线程模式么(p ...
spring使用注解暴露remoting服务 -
wangyujie0431:
<div class="quote_title ...
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 ^_^,我 是 菜 鸟,别喷哈.....
非常感谢

相关推荐
1. **Spring注解配置**: - `@Configuration`:标记一个类为Spring配置类,可替代传统的XML配置。 - `@ComponentScan`:用于扫描指定包下的所有@Component及其子注解(如@Service、@Repository、@Controller)的类...
服务器端会暴露一些服务对象,而客户端则可以通过Remoting接口来调用这些服务。这个示例可能包含详细的注释,帮助初学者理解Remoting的工作原理,包括通道配置、对象激活、方法调用等关键概念。 标签中提到了".NET ...
在本文中,我们将探讨如何将Direct Web Remoting (DWR) 3.0与Spring 2.5框架整合,并利用注解(Annotation)进行配置。DWR是一个允许JavaScript与Java服务器端进行交互的库,而Spring 2.5引入了对注解的强大支持,...
例如,我们可以使用`@Component`、`@Service`、`@Repository`和`@Controller`等注解标记我们的类,让Spring自动发现并管理它们。 接下来,我们需要配置DWR。DWR的配置主要包含两个部分:`dwr.xml`和`web.xml`。在`...
4. **注解Java类**:在需要暴露给DWR的Java类上使用`@RemoteProxy`注解,并可以自定义其在客户端的JavaScript接口名。 5. **编写JavaScript**:在客户端的JavaScript代码中,可以直接使用DWR生成的接口调用服务器端...
Spring RMI服务是一种在Java平台上实现远程方法调用(Remote Method Invocation, RMI)的技术,它允许分布式系统中的不同组件通过网络进行通信。在Spring框架的支持下,我们可以更方便地将服务发布为RMI服务,使得...
6. **使用服务**:现在,客户端可以通过Spring容器获取到的bean像调用本地方法一样调用远程服务了。 ```java HelloService helloService = (HelloService) context.getBean("helloServiceProxy"); String result ...
- 使用Spring的`@WebService`注解在接口上声明Web服务,然后创建其实现类。 - 将服务绑定到XFire,这通常通过在Spring配置文件中配置`XFireWebServiceExporter`完成。 3. **Web服务客户端**: - 客户端有两种...
标题 "Spring+DWR 全注解版" 暗示了这个压缩包包含了一个使用Spring框架和Direct Web Remoting (DWR) 技术的示例应用,且该应用主要依赖注解来配置和管理组件。DWR是一种在Web应用程序中实现AJAX功能的开源库,它...
- **使用Spring托管服务**:将服务实现bean添加到Spring容器中,以便Spring可以管理和暴露这个服务。 - **配置XFire**:配置XFire以使用Spring提供的服务实现,这样XFire就能处理HTTP请求并调用相应的服务方法。 ...
这些服务通常是Spring的bean,通过`@Service`或`@Component`注解标记,并使用`@RemoteMethod`注解来指定可暴露给Flex的方法。 3. **消息传递**: BlazeDS支持两种主要的消息传递机制:Remoting和Pub/Sub(发布/...
- **配置DWR Annotation Config**:利用`<dwr:annotation-config/>`标签启用注解支持,使得开发者能够使用`@RemoteProxy`和`@RemoteMethod`等注解来标注需要暴露给客户端的方法。 ```xml <!-- 配置DWR注解支持 -->...
1. **配置Spring容器**:在Spring配置文件(如`applicationContext.xml`)中,定义一个`XFireServiceExporter` bean,它会负责暴露你的服务为Web服务。例如: ```xml <bean id="xfireServiceExporter" class="org....
你可以使用 `<flex:remoting-destination>` 标签来配置服务的暴露,如下面的例子所示: ```xml <flex:remoting-destination ref="userService" endpoint="httpEndpoint" /> ``` 4. **配置 BlazeDS**:在 `...
3. **配置 Spring**:在 Spring 的配置文件中,定义一个 `XFireServiceExporter` bean 来暴露服务,同时配置 XFire 客户端工厂以便消费服务。 4. **注册服务**:使用 `@Service` 或 `@WebService` 注解标记服务实现...
通过在控制器或服务类上使用`@RemotingDestination`注解,可以方便地将Spring管理的Beans暴露给Flex客户端调用。 #### 四、使用Spring Security保护BlazeDS Destinations **配置Spring Security Integration:** ...
`spring-jmx.jar`提供了对JMX的集成,使得Spring应用可以暴露管理接口,方便监控和管理。 #### spring-jms.jar 消息传递是企业级应用中常见的通信模式。`spring-jms.jar`为Java Messaging Service(JMS)提供了...
- 使用Spring的`@Service`和`@Transactional`注解来标记服务类。 6. **数据绑定和事件处理**: - 在Flex客户端,通过ActionScript类绑定到Spring服务,通常使用`mx.rpc.remoting.RemoteObject`。 - 实现事件处理...