微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

WebService Resetful框架 spring-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行,注入的serviceLogServiceserviceAppService这两个传统的service层bean.

然后对应的java代码也加入2bean的引用,

        @Autowired
	static ServiceLogService serviceLogService;

	@Autowired
	static ServiceAppService serviceAppService;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐