SpringBeanRouter 是一个非常有用的类。
SpringBeanRouter 继承了Spring的ApplicationContextAware 和BeanFactoryPostProcessor 接口。
一、首先要说明的是,Restlet中,所有的资源也就是url绑定的可以访问的类都是继承了ServerResource类。
二、SpringBeanRouter 继承的ApplicationContextAware 接口,可以将Spring的上下文应用环境ApplicationContext 传给SpringBeanRouter 。
三、SpringBeanRouter 继承的BeanFactoryPostProcessor 接口,可以在bean构造的之前调用postProcessBeanFactory 方法。
四、SpringBeanRouter 中的postProcessBeanFactory ()方法
1、将Spring中是ServerResource 的子类所有bean都找出来,如果bean name是以 / 开始的,就加到资源查找路径上。
2、将Spring中是Restlet 的子类所有bean都找出来,如果bean name是以 / 开始的,就加到资源查找路径上。
3、通过SpringBeanRouter 的Attachments 属性配置的bean。
通常情况下,采用继承 ServerResource 实现与业务相关的 Resource 。