最近再写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;