Announcement Announcement Module
Collapse
No announcement yet.
PropertyPlaceholderConfigurer throwing NullPointerException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • PropertyPlaceholderConfigurer throwing NullPointerException

    All,
    I'm trying to do something very simple.

    I have a JNDI URL passed in as a SystemProperty at Weblogic startup.
    -Doprisk.weblogic.jndi.url=t3://localhost:9020 weblogic.Server

    I'm trying to use this URL in my org.springframework.jndi.JndiTemplate bean. To do this, i have the following spring xml file:

    Code:
    <bean id="asyncJndiTemplate"		class="org.springframework.jndi.JndiTemplate">
    		<property name="environment">
    			<props>
    				<prop key="java.naming.factory.initial">
    					weblogic.jndi.WLInitialContextFactory
    				</prop>
    				<prop key="java.naming.provider.url">
    					${oprisk.weblogic.jndi.url}
    					<!--t3://localhost:9020-->
    
    				</prop>
    			</props>
    		</property>
    	</bean>
    
    <bean id="propertyPlaceholderConfigurer"
    		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    		<property name="searchSystemEnvironment">
    			<value>false</value>
    		</property>
    	</bean>
    The problem is that PropertyPlaceholderConfigurer throws NullPointerEx.

    Code:
    Caused by: java.lang.NullPointerException
            at java.lang.StringBuffer.<init>(StringBuffer.java:130)
            at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.parseStringValue(PropertyPlaceholderConfigurer.java:270)
            at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer$PlaceholderResolvingBeanDefinitionVisitor.resolveStringValue(PropertyPlaceholderConfigurer.java:401)
            at org.springframework.beans.factory.config.BeanDefinitionVisitor.resolveValue(BeanDefinitionVisitor.java:143)
            at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitPropertyValues(BeanDefinitionVisitor.java:89)
            at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitBeanDefinition(BeanDefinitionVisitor.java:59)
            at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:246)
            at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:75)
            at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:422)
            at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:334)
            at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:241)
            at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184)
            at org.springframework.web.context.ContextLoaderServlet.init(ContextLoaderServlet.java:82)
            at javax.servlet.GenericServlet.init(GenericServlet.java:258)
            at weblogic.servlet.internal.ServletStubImpl$ServletInitAction.run(ServletStubImpl.java:1028)
            at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
            at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
            at weblogic.servlet.internal.ServletStubImpl.createServlet(ServletStubImpl.java:904)
            at weblogic.servlet.internal.ServletStubImpl.createInstances(ServletStubImpl.java:883)
            at weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl.java:822)
            at weblogic.servlet.internal.WebAppServletContext.preloadServlet(WebAppServletContext.java:3333)
            at weblogic.servlet.internal.WebAppServletContext.preloadServlets(WebAppServletContext.java:3290)
            at weblogic.servlet.internal.WebAppServletContext.preloadServlets(WebAppServletContext.java:3276)
    If i take away the reference to the PropertyPlaceholderConfigurer and hardcode the JNDI URL in my XML, it works fine. But as soon as I reference the PropertyPlaceholderConfigurer, I start seeing the exception.

    I'm sure I'm doing something incredibly stupid, but I can't figure out what it is. Any ideas anybody?

    Any help is appreciated. Thanks.

  • #2
    From the code it's the property-placeholder-to-be-resolved that's null. So maybe your notation of

    Code:
    <prop key="java.naming.provider.url">
    	${oprisk.weblogic.jndi.url}
    	<!--t3://localhost:9020-->
    
    </prop>
    is confusing Spring. Try to write it like

    Code:
    <prop key="java.naming.provider.url">${oprisk.weblogic.jndi.url}</prop>
    If that's working I would raise an issue in Jira since that would be a bit too restrict IMO. NPE is bad in any case anyway.

    Jörg

    Comment


    • #3
      Nope, doesn't work.

      I'm using 2 spring XML files in my web.xml, I have PropertPlaceHolderConfigurers defined in each. I'm think that's causing the problem, as if I include just 1 spring XML file, it works correctly, if I include both, it throws exceptions.

      What's the correct way to use PropertyPlaceHolderConfigurer with multiple bean defn files? Use 1 for all, 1 for each?

      TIA for any help.

      Regards.

      Comment


      • #4
        You could use one for all.
        One idea to use one for each is to have for your PropertyPlaceholderConfigurers different prefixes: http://www.springframework.org/docs/...a.lang.String)

        Comment


        • #5
          As long as you aren't using container-heirarchies you should be able to use one for all of them.
          http://www.springframework.org/docs/...postprocessors
          Last edited by karldmoore; Aug 27th, 2007, 04:23 PM.

          Comment


          • #6
            container-hierarchies? sorry, i'm new to spring, i am not familiar with that term. can you please point me to some documentation on container-hierarchies?

            Comment


            • #7
              Yeah sure, the link I attached to the previous post should help and also this. I don't think it's a problem for you, but I thought it was worth mentioning.
              http://www.springframework.org/docs/...ml#mvc-servlet
              Last edited by karldmoore; Aug 27th, 2007, 04:22 PM.

              Comment


              • #8
                looks like container-hierarchies are related with spring mvc. i'm not using spring mvc, i'm using struts. could that cause any issues with PPHC?

                My web.xml has the following entries:

                Code:
                <servlet>
                	  <servlet-name>context</servlet-name>
                  	  <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
                  	  <load-on-startup>1</load-on-startup>
                </servlet> 
                  
                  <context-param>
                  	<param-name>contextConfigLocation</param-name>
                 	<param-value>/WEB-INF/hierAsynContext.xml</param-value>
                  </context-param>
                
                <servlet>
                    <servlet-name>action</servlet-name>
                    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
                    <init-param>
                      <param-name>config</param-name>
                      <param-value>/WEB-INF/struts-config.xml</param-value>
                    </init-param>
                    <init-param>
                      <param-name>debug</param-name>
                      <param-value>1</param-value>
                    </init-param>
                    <init-param>
                      <param-name>detail</param-name>
                      <param-value>1</param-value>
                    </init-param>
                    <load-on-startup>2</load-on-startup>
                  </servlet>

                in my struts-config xml file, i have

                Code:
                <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
                <set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml, /WEB-INF/action-servlet.xml" />
                </plug-in>
                Give this kind of setup, where should i be defining PPHC? Once only? If so, in which XML file?
                Regardless of how I do it, PPHC throws NullPointerException.

                Comment


                • #9
                  I'm not sure since I'm not familiar with the ContextLoaderPlugin but you will probably end up with 2 contexts, which also probably create a hierarchy. The Struts documentation should have something on this.

                  Anyway, the PPHC has to go into the context where place holders need to be replaced. If I'm not completely you need one for each context also in a hierarchy.

                  Joerg

                  Comment

                  Working...
                  X