buffalo与spring的集成应该都是bean注入的!
而不要使用buffalo-service.properties文件的!
另外你可以看些贴子:
http://www.zhoujin.com/read.php?81
里面有详细和说明!
另外如果要使用aop方式也是可以的!
On 7月26日, 上午8时50分, "
acaleph2...@gmail.com" <
acaleph2...@gmail.com>
wrote:
> 我对BUFFALO配置的认识如下 :BUFFALO不与其它框架集成的配置,三个步骤应该可以了:
> -------------------------------------------------------------------------------------------------------------------------------
> 1 在web.xml注册并启动net.buffalo.web.servlet.ApplicationServlet
> 2 在buffalo-service.properties文档中声明用户自定义的Seervice.
> 3 在页面中创建BUFFALO对象,然后通过这个对象,引用用户定义的Service就可以了。
> -------------------------------------------------------------------------------------------------------------------------------
> 为了应用Spring的一些特性,遵循Spring工厂的原理,用户需要在Spring上下文中定义一个BEAN,如果想引用持久层对象,就在BEAN
> 中用REF来引入:
> -------------------------------------------------------------------------------------------------------------------------------
> <bean name="systemService"
> class="com.abc.system.service.impl.SystemService">
> <property name="commonDao" ref="commonDao" />
> -------------------------------------------------------------------------------------------------------------------------------
> 然后在SystemService类中,引用commonDao的接口:private ICommonDao commonDao。
> -------------------------------------------------------------------------------------------------------------------------------
> 问题:
> -------------------------------------------------------------------------------------------------------------------------------
> 1 按照普通配置,BUFFALO可以工作。
> 2 如果应用commonDao,失败。这是什么原因呢?
> -------------------------------------------------------------------------------------------------------------------------------
> > > > -----------------------------------------------------------------------------------------------------------------------
> > > > public class SystemService implements ISystemService {
>
> > > > public SystemService() {
> > > > System.out.println("Here is buffalo servive1.");
> > > > }
>
> > > > public int getInteger(String a) {
> > > > System.out.println("Here is buffalo servive2.");
> > > > return 1;
> > > > }
>
> > > > }
> > > > -----------------------------------------------------------------------------------------------------------------------
> > > > 2 修改了Servlet的配置:
> > > > -----------------------------------------------------------------------------------------------------------------------
> > > > <servlet>
> > > > <servlet-name>easybea</servlet-name>
> > > > <servlet-class>
> > > > net.buffalo.web.servlet.ApplicationServlet
> > > > </servlet-class>
> > > > <load-on-startup>1</load-on-startup>
> > > > </servlet>
> > > > -----------------------------------------------------------------------------------------------------------------------
> > > > 3 可以启动,SystemService正常工作:打印出:System.out.println("Here is buffalo
> > > > servive1.");
> > > > -----------------------------------------------------------------------------------------------------------------------
> > > > 4 Call Service中的方法,失败(buffalo.js已经成功载入):出现"页面错误"提示,后台没有响应:
> > > > -----------------------------------------------------------------------------------------------------------------------
> > > > function buffalos(){
> > > > var a = "22";
> > > > buffalo.remoteCall("systemService.getInteger", [a], function(reply) {
> > > > var re=reply.getResult();
> > > > alert(re);
> > > > });
> > > > }
> > > > -----------------------------------------------------------------------------------------------------------------------
> > > >> > -------------------------------------------------------------------------------------------------------
> > > >> > <servlet>
> > > >> > <servlet-name>buffalo</servlet-name>
> > > >> > <servlet-class>
> > > >> > net.buffalo.web.servlet.ApplicationServlet
> > > >> > </servlet-class>
> > > >> > </servlet>
> > > >> > <servlet-mapping>
> > > >> > <servlet-name>buffalo</servlet-name>
> > > >> > <url-pattern>/buffalo/*</url-pattern>
> > > >> > </servlet-mapping>
> > > >> > -------------------------------------------------------------------------------------------------------
> > > >> > Step 2 写一个简单的ISystemService(空的)
> > > >> > -------------------------------------------------------------------------------------------------------
> > > >> > public interface ISystemService {}
> > > >> > -------------------------------------------------------------------------------------------------------
> > > >> > Step 3 实现这个接口
> > > >> > -------------------------------------------------------------------------------------------------------
> > > >> > public class SystemService implements ISystemService {
> > > >> > Map session = (Map) RequestContext.getContext().getSession();
>
> > > >> > AdminUser user = (AdminUser) (((java.util.Map) session)
> > > >> > .get(com.abc.core.util.Globals.COOKIE));
>
> > > >> > public SystemService() {
> > > >> > System.out.println("Here is buffalo servive.");}
>
> > > >> > -------------------------------------------------------------------------------------------------------
> > > >> > Step 4 在applicationContext.xml中增加:
> > > >> > -------------------------------------------------------------------------------------------------------
> > > >> > <bean name="systemService"
> > > >> > class="com.abc.system.service.impl.SystemService">
> > > >> > </bean>
> > > >> > <bean name="buffaloConfigBean"
> > > >> > class="net.buffalo.service.BuffaloServiceConfigurer">
> > > >> > <property name="services">
> > > >> > <map>
> > > >> > <entry key="springSimpleService">
> > > >> > <ref bean="systemService" />
> > > >> > </entry>
>
> > > >> > </map>
> > > >> > </property>
> > > >> > </bean>
> > > >> > -------------------------------------------------------------------------------------------------------
> > > >> > 报错:
> > > >> > -------------------------------------------------------------------------------------------------------
> > > >> > ERROR - Context initialization failed
> > > >> > org.springframework.beans.factory.BeanCreationException: Error
> > > >> > creating bean with name 'systemService' defined in class path resource
> > > >> > [applicationContext.xml]: Instantiation of bean failed; nested
> > > >> > exception is org.springframework.beans.BeanInstantiationException:
> > > >> > Could not instantiate bean class
> > > >> > [com.abc.system.service.impl.SystemService]: Constructor threw
> > > >> > exception; nested exception is java.lang.NullPointerException
> > > >> > at
> > > >> > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactor--y.instantiateBean(AbstractAutowireCapableBeanFactory.java:
> > > >> > 883)
> > > >> > at
> > > >> > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactor--y.createBeanInstance(AbstractAutowireCapableBeanFactory.java:
> > > >> > 839)
> > > >> > at
> > > >> > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactor--y.doCreateBean(AbstractAutowireCapableBeanFactory.java:
> > > >> > 440)
> > > >> > at
> > > >> > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactor--y
> > > >> > $1.run(AbstractAutowireCapableBeanFactory.java:409)
> > > >> > at java.security.AccessController.doPrivileged(Native Method)
> > > >> > at
> > > >> > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactor--y.createBean(AbstractAutowireCapableBeanFactory.java:
> > > >> > 380)
> > > >> > at org.springframework.beans.factory.support.AbstractBeanFactory
> > > >> > $1.getObject(AbstractBeanFactory.java:264)
> > > >> > at
> > > >> > org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getS--ingleton(DefaultSingletonBeanRegistry.java:
> > > >> > 221)
> > > >> > at
> > > >> > org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(Abs--tractBeanFactory.java:
> > > >> > 261)
> > > >> > at
> > > >> > org.springframework.beans.factory.support.AbstractBeanFactory.getBean(Abstr--actBeanFactory.java:
> > > >> > 185)
> > > >> > at
> > > >> > org.springframework.beans.factory.support.AbstractBeanFactory.getBean(Abstr--actBeanFactory.java:
> > > >> > 164)
> > > >> > at
>
> ...
>
> 阅读更多 >>- 隐藏被引用文字 -
>
> - 显示引用的文字 -