buffalo与spring联合开发
Buffalo是 一个为java web项目而设计的轻量级AJAX框架。它是开源的(Apache License 2.0),最主要的是它使用起来方便而且学起来易上手。它主要解决在j2ee ajax开发中的常见问题。
Spring 是一个时下非常活跃的开源项目,是一个基于IoC和AOP技术的构架多层j2ee系统的框架。它模块化的很好,你在使用它是将会非常的自由,它从不强迫你必须在每一层中必须使用。
两个关注点完全不同,但非常实用的框架在项目的开发中肯定会用到,要将两这联合起来开发其实很简单:
1、开发对应的service,也就是java逻辑类;
2、在spring配置applicationContext.xml文件中申明该service:
<bean name="simpleService" class="net.buffalo.demo.simple.SimpleService"></bean>;
然后按如下方式声明引用:
<bean name="buffaloConfigBean" class="net.buffalo.service.BuffaloServiceConfigurer">
<property name="services">
<map>
<entry key="springSimpleService">
<ref bean="simpleService"/>
</entry>
</map>
</property>
</bean>
通过以上配置后,开发者不用再配置buffalo-service.properties文件了,使用applicationContext.xml替代它。其中引用到的bean可以是任意被Spring托管的bean。在web页面的调用不需要做什么改变。
3、当然,在web.xml中必须引入对buffalo的支持,申明spring配置文件,如下:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml(来源 www.iocblog.net)
</param-value>
</context-param>
<servlet>
<servlet-name>bfapp</servlet-name>
<servlet-class>net.buffalo.web.servlet.ApplicationServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>bfapp</servlet-name>
<url-pattern>/bfapp/*</url-pattern>
</servlet-mapping>
文章整理:iocblog
版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。