Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '_messageBroker': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanInitializationException: MessageBroker initialization failed; nested exception is java.lang.NullPointerException
或
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '_messageBrokerDefaultHandlerMapping': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '_messageBroker': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanInitializationException: MessageBroker initialization failed; nested exception is java.lang.NullPointerException
在Spring的官网上有类似这样回答的
http://forum.springsource.org/showthread.php?71492-Issue-upgrading-to-RC1-Init-method-failed
说在spring-flex的配置文件里把
改成
但是不管用,并且即便管用,也不会解决根本问题,不过看大概的意思,明白了
报这个错误的根本原因就是,在没有使用web.xml当作Web项目进行初始化的时候,若加载Spring-BlazeDS的配置文件,就会加载相关的BlazeDS相应的监听和初始化,从而引发空指针错误
解决办法其实有很多
目的就是避免加载Spring-BlazeDS的配置文件,从而不初始化BlazeDS。
在JUnit中
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "/applicationContext-Dao.xml" ,"/applicationContext-Service.xml"})
通过这种方法分开来写装载的配置文件,而取代通配符
再或者,使用通配符的时候,把名字和其他配置文件排除在外,使之执行不加载相应的配置文件。
-------------------------
若想使用通配符配置相应文件,则,可以在web.xml中分开进行注册
Spring flex Dispatcher Servlet org.springframework.web.servlet.DispatcherServlet contextConfigLocation classpath*:flexContext.xml 1 Spring flex Dispatcher Servlet /messagebroker/*
也可分开配置
contextConfigLocation classpath*:conf/spring/applicationContext-Dao.xml, classpath*:conf/spring/applicationContext-Service.xml, classpath*:conf/spring/applicationContext-XXX.xml,
其他配置文件可以按相同方式配置,也可以如下
contextConfigLocation classpath*:applicationContext*.xml org.springframework.web.context.ContextLoaderListener
只要这里面加载的文件和servlet配置的文件不发生冲突,不重复,就不会报错误,否则会报错