PDA

View Full Version : NullPointerException



ericeberry
Apr 26th, 2009, 11:34 PM
I am getting the following NullPointerException:

org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name '_messageBrokerDefaultHandlerMapping': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name '_messageBroker': Invocation of init method failed; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:480)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 64)
at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:261 )
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:429)
at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:728)
at org.springframework.osgi.context.support.AbstractD elegatedExecutionApplicationContext.access$1600(Ab stractDelegatedExecutionApplicationContext.java:69 )
at org.springframework.osgi.context.support.AbstractD elegatedExecutionApplicationContext$4.run(Abstract DelegatedExecutionApplicationContext.java:355)
at org.springframework.osgi.util.internal.PrivilegedU tils.executeWithCustomTCCL(PrivilegedUtils.java:85 )
at org.springframework.osgi.context.support.AbstractD elegatedExecutionApplicationContext.completeRefres h(AbstractDelegatedExecutionApplicationContext.jav a:320)
at org.springframework.osgi.extender.internal.depende ncies.startup.DependencyWaiterApplicationContextEx ecutor$CompleteRefreshTask.run(DependencyWaiterApp licationContextExecutor.java:136)
at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name '_messageBroker': Invocation of init method failed; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1338)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:473)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 64)
at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:261 )
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.Abstract BeanFactory.isSingleton(AbstractBeanFactory.java:3 66)
at org.springframework.context.support.AbstractApplic ationContext.isSingleton(AbstractApplicationContex t.java:896)
at org.springframework.web.servlet.handler.AbstractUr lHandlerMapping.registerHandler(AbstractUrlHandler Mapping.java:296)
at org.springframework.web.servlet.handler.SimpleUrlH andlerMapping.registerHandlers(SimpleUrlHandlerMap ping.java:129)
at org.springframework.web.servlet.handler.SimpleUrlH andlerMapping.initApplicationContext(SimpleUrlHand lerMapping.java:103)
at org.springframework.context.support.ApplicationObj ectSupport.initApplicationContext(ApplicationObjec tSupport.java:119)
at org.springframework.web.context.support.WebApplica tionObjectSupport.initApplicationContext(WebApplic ationObjectSupport.java:69)
at org.springframework.context.support.ApplicationObj ectSupport.setApplicationContext(ApplicationObject Support.java:73)
at org.springframework.context.support.ApplicationCon textAwareProcessor.postProcessBeforeInitialization (ApplicationContextAwareProcessor.java:70)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyBeanPostProcessors BeforeInitialization(AbstractAutowireCapableBeanFa ctory.java:350)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1331)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:473)
... 16 more
Caused by: java.lang.NullPointerException
at org.springframework.flex.messaging.config.FlexConf igurationManager.getMessagingConfiguration(FlexCon figurationManager.java:64)
at org.springframework.flex.messaging.MessageBrokerFa ctoryBean.afterPropertiesSet(MessageBrokerFactoryB ean.java:167)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1369)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1335)
... 37 more


Here are my config files:
web.xml
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>example-servlet</display-name>
<servlet>
<description>The OSGI example servlet</description>
<display-name>example</display-name>
<servlet-name>example</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.osgi.web.context.support.OsgiB undleXmlWebApplicationContext</param-value>
</init-param>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/META-INF/spring/exampleweb-context.xml,/META-INF/spring/exampleweb-osgi-context.xml,/META-INF/spring/exampleweb-flex-context.xml</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>example</servlet-name>
<url-pattern>/messagebroker/*</url-pattern>
</servlet-mapping>
</web-app>


exampleweb-flex-context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:flex="http://www.springframework.org/schema/flex" xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/flex http://www.springframework.org/schema/flex/spring-flex-1.0.xsd" default-autowire="byName">
<flex:message-broker/>
<flex:remote-service ref="exampleService"/>
</beans>


services-config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<services-config>
<channels>
<channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
<endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
<properties>
<polling-enabled>false</polling-enabled>
</properties>
</channel-definition>
</channels>
</services-config>



I traced it to the MessageBrokerFactoryBean servletContext is null. Is there some configuration parameter that is not set correctly?

ericeberry
Apr 26th, 2009, 11:49 PM
I forgot to mention that I am running it in OSGI. Here is the manifest for my war:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: 1.6.0_13 (Sun Microsystems Inc.)
Built-By: eberry0006e
Build-Jdk: 1.6.0_13
Private-Package: com.ccadllc.osgi.example.web.app.internal.servlet; ver
sion="1.0.7-SNAPSHOT",WEB-INF.flex;version="1.0.7-SNAPSHOT",WEB-INF;v
ersion="1.0.7-SNAPSHOT"
Tool: Bnd-0.0.311
Bundle-Name: osgiexampleweb
Web-ContextPath: /example
Require-Bundle: com.springsource.flex.messaging,org.springframewor k.flex
Bundle-Vendor: CCAD, LLC
Bundle-BuildNumber: 68
Bundle-Version: 1.0.7.SNAPSHOT
Bnd-LastModified: 1240802405858
Bundle-ManifestVersion: 2
Bundle-Description: The CCAD OSGi exampleweb library contains a simple
web servlet that give an example on how to create an osgi servlet.
You can use this project as a template for creating your web project.
Import-Package: com.ccadllc.mediacipher.common.infrastructure.secu rity
;version="1.1",com.ccadllc.osgi.example;version="1.0",com.ccadllc.osg
i.example.common.domain.persist;version="1.0",com.ccadllc.osgi.exampl
e.common.domain.service;version="1.0",javax.annotation,javax.servlet.
http;version="2.5",org.springframework.beans.factory.aspectj;version =
"2.5",org.springframework.beans.factory.config;version="2.5",org.spri
ngframework.osgi.web.context.support;version="1.1",org.springframewor
k.stereotype;version="2.5",org.springframework.web.bind.annotation;ve
rsion="2.5",org.springframework.web.servlet;version="2.5",org.springf
ramework.web.servlet.handler;version="2.5",org.springframework.web.se
rvlet.mvc;version="2.5"
Bundle-SymbolicName: com.ccadllc.osgi.example.web
Bundle-DocURL: http://www.ccadllc.com

ericeberry
Apr 27th, 2009, 11:31 AM
exampleweb-context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd" default-autowire="byName">
<context:component-scan base-package="com.ccadllc.osgi.example.web"/>
<bean id="osgiexampleProperties" class="org.springframework.beans.factory.config.Propertie sFactoryBean">
<property name="location" value="classpath:/com/ccadllc/osgi/example/osgiexample.properties"/>
</bean>
</beans>


exampleweb-osgi-context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:osgi="http://www.springframework.org/schema/osgi" xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/osgi
http://www.springframework.org/schema/osgi/spring-osgi.xsd" default-autowire="byName">
<osgi:reference id="exampleService" interface="com.ccadllc.osgi.example.common.domain.service.Exa mpleService"/>
</beans>

ericeberry
Apr 28th, 2009, 01:47 PM
I found the issue. I had my spring files defined in /META-INF/spring. Spring DM was picking these up outside of tomcat and trying to instantiate the spring beans. I moved my spring files to /WEB-INF/spring and it fixed the problem. The spring beans are now being instantiated inside tomcat.

cholm
May 14th, 2009, 04:14 PM
I had a somewhat similar issue with an NPE coming from a few lines down in the same method. The issue was that I did not have a deafult MessagingService defined in my BlazeDS config files (no messaging-config.xml as I was only working with RPC calls), nor did I have one configured with a <flex:messaging-service/> bean definition. Adding the default <flex:messaging-service/> to my <flex:message-broker/> config resolved the issue. Thought this may be useful for anyone stumbling upon this post to resolve that issue, as I did.