Buffalo与Spring集成问题

16 views
Skip to first unread message

acale...@gmail.com

unread,
Jul 25, 2008, 3:02:12 AM7/25/08
to buffalo与Amowa
在已经配置好(工作正常)的Spring下增加Buffalo集成:
Step 1 在web.xml中增加:
-----------------------------------------------------------------------------------------------------
<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.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:
883)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:
839)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:
440)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:
380)
at org.springframework.beans.factory.support.AbstractBeanFactory
$1.getObject(AbstractBeanFactory.java:264)
at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:
221)
at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:
261)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:
185)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:
164)
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:
429)
at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:
729)
at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:
381)
at
org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:
255)
at
org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:
199)
at
org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:
45)
at
org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:
540)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:135)
at
org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:
1220)
at
org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:
510)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:
448)
at
org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:
39)
at
org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:
130)
at org.mortbay.jetty.Server.doStart(Server.java:222)
at
org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:
39)
at com.abc.jetty.RunJetty.main(RunJetty.java:20)
-----------------------------------------------------------------------------------------------------

Michael Chen

unread,
Jul 25, 2008, 3:05:10 AM7/25/08
to am...@googlegroups.com
Map session = (Map) RequestContext.getContext().getSession();

AdminUser user = (AdminUser) (((java.util.Map) session)
.get(com.abc.core.util.Globals.COOKIE));

getSession()只有在方法执行过程中才有,构造器生命周期内不会有的。尝试把这段代码写到方法里面去吧。

2008/7/25 acale...@gmail.com <acale...@gmail.com>:

--
Michael Chen
--------------------------------
Blog: http://michael.nona.name
MSN: jzch...@hotmail.com

chirs...@gmail.com

unread,
Jul 25, 2008, 3:25:26 AM7/25/08
to buffalo与Amowa
你要检查session可以用另外一个方法来处理,
不要使用我以前没有使用spring时的方法了!

On 7月25日, 下午3时02分, "acaleph2...@gmail.com" <acaleph2...@gmail.com>
wrote:
> 在已经配置好(工作正常)的Spring下增加Buffalo集成:
> Step 1 在web.xml中增加:
> ------------------------------------------------------------------------------------------------------
> <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
> org.springframework.beans.factory.support.DefaultListableBeanFactory.preIns-tantiateSingletons(DefaultListableBeanFactory.java:
> 429)
> at
> org.springframework.context.support.AbstractApplicationContext.finishBeanFa-ctoryInitialization(AbstractApplicationContext.java:
> 729)
> at
> org.springframework.context.support.AbstractApplicationContext.refresh(Abst-ractApplicationContext.java:
> 381)
> at
> org.springframework.web.context.ContextLoader.createWebApplicationContext(C-ontextLoader.java:
> 255)
> at
> org.springframework.web.context.ContextLoader.initWebApplicationContext(Con-textLoader.java:
> 199)
> at
> org.springframework.web.context.ContextLoaderListener.contextInitialized(Co-ntextLoaderListener.java:
> 45)
> at
> org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:
> 540)
> at org.mortbay.jetty.servlet.Context.startContext(Context.java:135)
> at
> org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:
> 1220)
> at
> org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:
> 510)
> at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:
> 448)
> at
> org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:
> 39)
> at
> org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:
> 130)
> at org.mortbay.jetty.Server.doStart(Server.java:222)
> at
> org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:
> 39)
> at com.abc.jetty.RunJetty.main(RunJetty.java:20)
> ------------------------------------------------------------------------------------------------------

chirs...@gmail.com

unread,
Jul 25, 2008, 3:35:49 AM7/25/08
to buffalo与Amowa
另外buffalo对于spring加载方式也是有要求,还有ApplicationServlet启动顺序也是有要求的,不然你不能拿注入
service的!

On 7月25日, 下午3时02分, "acaleph2...@gmail.com" <acaleph2...@gmail.com>
wrote:
> 在已经配置好(工作正常)的Spring下增加Buffalo集成:
> Step 1 在web.xml中增加:
> ------------------------------------------------------------------------------------------------------
> <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
> 45)
> at
> org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:
> 540)
> at org.mortbay.jetty.servlet.Context.startContext(Context.java:135)
> at
> org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:
> 1220)
> at
> org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:
> 510)
> at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:
> 448)
> at
> org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:
> 39)
> at
> org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:
> 130)
> at org.mortbay.jetty.Server.doStart(Server.java:222)
> at
> org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:
> 39)
> at com.abc.jetty.RunJetty.main(RunJetty.java:20)
> ------------------------------------------------------------------------------------------------------

acale...@gmail.com

unread,
Jul 25, 2008, 4:46:53 AM7/25/08
to buffalo与Amowa
做了如下调整:
1 修改SystemService代码:
----------------------------------------------------------------------------------------------------------------------
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);
});
}
----------------------------------------------------------------------------------------------------------------------

On Jul 25, 3:35 pm, "chirs.z...@gmail.com" <chirs.z...@gmail.com>
wrote:

Michael Chen

unread,
Jul 25, 2008, 6:38:37 AM7/25/08
to am...@googlegroups.com
buffalo对象是怎么创建的?将那个URL扔到浏览器里面看看,能不能访问?如果不出现404错误,说明配置正确。

2008/7/25 acale...@gmail.com <acale...@gmail.com>:

--

acale...@gmail.com

unread,
Jul 25, 2008, 7:11:33 AM7/25/08
to buffalo与Amowa
BUFFALO对象应该已经创建成功了(客端),要不然,就不会调用BUFFAO的提示了:页面有错误。。。

On Jul 25, 3:38 am, "Michael Chen" <mechil...@gmail.com> wrote:
> buffalo对象是怎么创建的?将那个URL扔到浏览器里面看看,能不能访问?如果不出现404错误,说明配置正确。
>
> 2008/7/25 acaleph2...@gmail.com <acaleph2...@gmail.com>:
> MSN: jzche...@hotmail.com

acale...@gmail.com

unread,
Jul 25, 2008, 8:50:39 PM7/25/08
to buffalo与Amowa
我对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,失败。这是什么原因呢?
------------------------------------------------------------------------------------------------------------------------------

On Jul 25, 7:11 pm, "acaleph2...@gmail.com" <acaleph2...@gmail.com>
wrote:

chirs

unread,
Jul 26, 2008, 5:55:07 AM7/26/08
to buffalo与Amowa
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,失败。这是什么原因呢?
> -------------------------------------------------------------------------------------------------------------------------------
>
> On Jul 25, 7:11 pm, "acaleph2...@gmail.com" <acaleph2...@gmail.com>
> wrote:
>
>
>
> > BUFFALO对象应该已经创建成功了(客端),要不然,就不会调用BUFFAO的提示了:页面有错误。。。
>
> > On Jul 25, 3:38 am, "Michael Chen" <mechil...@gmail.com> wrote:
>
> > > buffalo对象是怎么创建的?将那个URL扔到浏览器里面看看,能不能访问?如果不出现404错误,说明配置正确。
>
> > > 2008/7/25 acaleph2...@gmail.com <acaleph2...@gmail.com>:
>
> > > > 做了如下调整:
> > > > 1 修改SystemService代码:
> > > > -----------------------------------------------------------------------------------------------------------------------
> > > > 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);
> > > > });
> > > > }
> > > > -----------------------------------------------------------------------------------------------------------------------
>
> > > > On Jul 25, 3:35 pm, "chirs.z...@gmail.com" <chirs.z...@gmail.com>
> > > > wrote:
> > > >> 另外buffalo对于spring加载方式也是有要求,还有ApplicationServlet启动顺序也是有要求的,不然你不能拿注入
> > > >> service的!
>
> > > >> On 7月25日, 下午3时02分, "acaleph2...@gmail.com" <acaleph2...@gmail.com>
> > > >> wrote:
>
> > > >> > 在已经配置好(工作正常)的Spring下增加Buffalo集成:
> > > >> > Step 1 在web.xml中增加:
> > > >> > -------------------------------------------------------------------------------------------------------
> > > >> > <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
>
> ...
>
> 阅读更多 >>- 隐藏被引用文字 -
>
> - 显示引用的文字 -

chirs

unread,
Jul 26, 2008, 5:58:25 AM7/26/08
to buffalo与Amowa
buffalo与spring集成应该中间有一个过渡过程
意思是:具体暴露给buffalo调用的应该是一个javabean,这个里面具体调用其他的spirng bean

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,失败。这是什么原因呢?
> -------------------------------------------------------------------------------------------------------------------------------
>
> On Jul 25, 7:11 pm, "acaleph2...@gmail.com" <acaleph2...@gmail.com>
> wrote:
>
>
>
> > BUFFALO对象应该已经创建成功了(客端),要不然,就不会调用BUFFAO的提示了:页面有错误。。。
>
> > On Jul 25, 3:38 am, "Michael Chen" <mechil...@gmail.com> wrote:
>
> > > buffalo对象是怎么创建的?将那个URL扔到浏览器里面看看,能不能访问?如果不出现404错误,说明配置正确。
>
> > > 2008/7/25 acaleph2...@gmail.com <acaleph2...@gmail.com>:
>
> > > > 做了如下调整:
> > > > 1 修改SystemService代码:
> > > > -----------------------------------------------------------------------------------------------------------------------
> > > > 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);
> > > > });
> > > > }
> > > > -----------------------------------------------------------------------------------------------------------------------
>
> > > > On Jul 25, 3:35 pm, "chirs.z...@gmail.com" <chirs.z...@gmail.com>
> > > > wrote:
> > > >> 另外buffalo对于spring加载方式也是有要求,还有ApplicationServlet启动顺序也是有要求的,不然你不能拿注入
> > > >> service的!
>
> > > >> On 7月25日, 下午3时02分, "acaleph2...@gmail.com" <acaleph2...@gmail.com>
> > > >> wrote:
>
> > > >> > 在已经配置好(工作正常)的Spring下增加Buffalo集成:
> > > >> > Step 1 在web.xml中增加:
> > > >> > -------------------------------------------------------------------------------------------------------
> > > >> > <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

acale...@gmail.com

unread,
Jul 27, 2008, 8:11:16 PM7/27/08
to buffalo与Amowa
我在调试过程中,也看了CHIRS的贴子(配置方式基本和你说的一样),也把buffalo-service.properties中注册的bean注
释掉后,发现systemService这个在applicationContext.xml中注入的bean不能工作了,而且还抛出异常:
net.buffalo.service.NoSuchServiceException: systemService,这说明这个BEAN没有注入
成功。
CHIRS所说的暴露给BUFFALO调用的JAVABEAN是例子中的simpleService吗?如果是,我的配置基本和CHIRS讲的一样,但
还是不能工作。
> ...
>
> read more >>

acale...@gmail.com

unread,
Jul 28, 2008, 10:19:12 PM7/28/08
to buffalo与Amowa
现在,我的例子中,可以肯定BUFFALO SERVICE注入,应该没有问题了。
但是,JS在CALL SERVICE时,创建的BUFFALO对象的写法,如果从buffalo-service.properties中获取(即不
与SPRING集成),和与SPRING集成后,以IOC方式获取,应该是不同的,否则,为什么SPRING找不到这个SERVICE BEAN呢?
前面以经提到了启动Buffalo servlet的Servlet映射是:abc,这样我在JS中创建Buffalo对象的写法就是:var
buffalo = new Buffalo("/abc");这种写法,如果不与SPRING集成,是可以CALL成功的,集成后,就CALL失败。
究竟怎么写对呢?

On Jul 28, 8:11 am, "acaleph2...@gmail.com" <acaleph2...@gmail.com>
wrote:
> ...
>
> read more >>

Michael Chen

unread,
Jul 29, 2008, 9:18:29 AM7/29/08
to am...@googlegroups.com
buffalo 被配置的url其实就是一个普通的url,先检测这个url能否被正常访问。例如,你的webapp被部署在

http://localhost:8080/yourapp/

在web.xml中,buffalo的ApplicationServlet被配置在/bfapp, 那么访问

http://localhost:8080/yourapp/bfapp/buffalo

你应该看到一个错误:buffalo worker support http POST only 而不是404错误。


确认上述无误之后,再看与Spring集成的部分。

一般说来,只要在webhttpcontext中能够找到Spring的ApplicationContext,
那么Spring无需特别配置。通过Spring的Servlet或者通过Listerner都可以达到这个目标。

然后,很重要的,需要在任意一个可以被Spring 加载的XML配置文件中,加入buffalo bean的申明:

<bean name="buffaloConfigBean"
class="net.buffalo.service.BuffaloServiceConfigurer">
<property name="services">
<map>

<entry key="testSpringService1"><ref bean="yourBeanId"/></entry>
<!-- oterh entries... -->
</map>
</property>
</bean>

这个bean的而意思是,当buffalo调用testSpringService1.XXX相关方法的时候,会调用到另外一个Spring配置好的YourBeanId.XXX方法。其他的,可以依次添加。

buffalo-server.properties和Spring配置的方式两者可以同时使用。不同的是,前者每次通过反射来创建一个新的Service,
生命周期由buffalo控制,后者通过Spring来提供实例,生命周期由Spring控制。

相关的链接:

http://buffalo.sourceforge.net/howto.html#4
http://lococode.javaeye.com/blog/69527

Michael Chen
--------------------------------
Blog: http://michael.nona.name

MSN: jzch...@hotmail.com

acale...@gmail.com

unread,
Jul 29, 2008, 9:08:25 PM7/29/08
to buffalo与Amowa
没错,就是这里的问题:原因是我对SPRING的理解不深,后来读了一下你的源码,才搞好:
----------------------------------------------------------------------------------------------------------------------
这个bean的而意思是,当buffalo调用testSpringService1.XXX相关方法的时候,会调用到另外一个Spring配置好的
YourBeanId.XXX方法。其他的,可以依次添加。
----------------------------------------------------------------------------------------------------------------------
或许因为是受buffalo-service.properties中配置配置语法的影响,或者思维定势,就直接引用了yourBeanId的XXX方
法了(实际当时配置时也很疑惑,为什么不直接把BUFFALO写的SERVICE做为SPRING BEAN使用呢?这样做是不是会产生与SPRING
耦合的情况,不利于扩展吧),这样,出现找不到SERVICE的情况了,我让源码打印出所有的已经注入的BUFFALO SERVICE,结果发现引用
方法错误才倒致这样的结果。


On Jul 29, 9:18 pm, "Michael Chen" <mechil...@gmail.com> wrote:
> buffalo 被配置的url其实就是一个普通的url,先检测这个url能否被正常访问。例如,你的webapp被部署在
>
> http://localhost:8080/yourapp/
>
> 在web.xml中,buffalo的ApplicationServlet被配置在/bfapp, 那么访问
>
> http://localhost:8080/yourapp/bfapp/buffalo
>
> 你应该看到一个错误:buffalo worker support http POST only 而不是404错误。
>
> 确认上述无误之后,再看与Spring集成的部分。
>
> 一般说来,只要在webhttpcontext中能够找到Spring的ApplicationContext,
> 那么Spring无需特别配置。通过Spring的Servlet或者通过Listerner都可以达到这个目标。
>
> 然后,很重要的,需要在任意一个可以被Spring 加载的XML配置文件中,加入buffalo bean的申明:
>
> <bean name="buffaloConfigBean"
> class="net.buffalo.service.BuffaloServiceConfigurer">
> <property name="services">
> <map>
> <entry key="testSpringService1"><ref bean="yourBeanId"/></entry>
> <!-- oterh entries... -->
> </map>
> </property>
> </bean>
>
> 这个bean的而意思是,当buffalo调用testSpringService1.XXX相关方法的时候,会调用到另外一个Spring配置好的YourBeanId.XXX方法。其他的,可以依次添加。
>
> buffalo-server.properties和Spring配置的方式两者可以同时使用。不同的是,前者每次通过反射来创建一个新的Service,
> 生命周期由buffalo控制,后者通过Spring来提供实例,生命周期由Spring控制。
>
> 相关的链接:
>
> http://buffalo.sourceforge.net/howto.html#4http://lococode.javaeye.com/blog/69527
>
> Michael Chen
> --------------------------------
> Blog:http://michael.nona.name
> MSN: jzche...@hotmail.com
Reply all
Reply to author
Forward
0 new messages