WebService Resetful框架 spring-bean的配置
发布时间:2020-12-16 23:18:19 所属栏目:安全 来源:网络整理
导读:最近再写 Restful 接口,我推荐一个不错的 restful 学习 demo, http://my.oschina.net/jiyayun/blog/146446 目前大多 j2ee 项目是 spring 接管 service 层和 dao 层, 前端时间一直头疼 restful 中无法获取 bean 的问题,只要打通这个“任督二脉”, 接下的
最近再写Restful接口,我推荐一个不错的restful学习demo, http://my.oschina.net/jiyayun/blog/146446 目前大多j2ee项目是spring接管service层和dao层, 前端时间一直头疼restful中无法获取bean的问题,只要打通这个“任督二脉”, 接下的来的开发任务都能如鱼入水。 先看?WEB-INF/restlet-servlet.xml?中的配置;
<?xml version="1.0"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd"> <bean name="root" class="org.restlet.ext.spring.SpringRouter"> <property name="attachments"> <map> <entry key="/query"> <bean class="org.restlet.ext.spring.SpringFinder"> <lookup-method name="create" bean="QueryResource" /> </bean> </entry> </map> </property> </bean> <bean id="QueryResource" class="com.restful.QueryResource" scope="prototype"> <property name="serviceLogService" ref="serviceLogService" /> <property name="serviceAppService" ref="serviceAppService" /> </bean> </beans> 其中?“root"bean存放map含有众多entry,拦截对应的请求链接。 关键在与倒数?3,4行,注入的serviceLogService和serviceAppService这两个传统的service层bean. 然后对应的java代码也加入2个bean的引用, @Autowired static ServiceLogService serviceLogService; @Autowired static ServiceAppService serviceAppService; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |