Results 1 to 7 of 7

Thread: Can i suppress the BeanFactory post-processors for 1 bean defn in Appl.Context?

  1. #1
    Join Date
    Mar 2008
    Location
    SF Bay Area, California
    Posts
    11

    Unhappy Can i suppress the BeanFactory post-processors for 1 bean defn in Appl.Context?

    I need to instantiate 1 Map<String,String> bean in my ApplicationContext.xml file that contains map entrys with value strings that contain html, with syntax for Freemarker variables, which is exactly the same as the placeholder syntax. I.E below in the Map bean definition the text contains ${User_Role} which is a freemarker variable that will be substituted by the freemarker engine at view rendering time.

    Loading ApplicationContext.xml fails with ...beans.factory.BeanDefinitionStoreException: with the error message "Could not resolve placeholder 'User_Role' which is throw from ...factory.config.PropertyPlaceholderConfigurer.pr ocessProperties() method.

    After reading the IOC Container docs, examining Spring sources and searching the forums, i have not been able to find anything on how to suppress the use of the PropertyPlaceholderConfigurer for so i can create this 1 bean and suppress having the map's xml definition (below) scanned for placeholder "substitutions", which can't be resolved.

    Is there some way to use a "BeanFactory" as a child context of the ApplicationContext and load this bean
    definition from it own "myOneBean.xml" bean config file and still create a bean i can then inject into
    the FreemarkerConfigurer?

    As i understand (poorly, no doubt) the BeanFactory does not support the PostProcessors that are preventing creating the bean with these strings in the Map.

    Or maybe there is some way to disable the PostProcessors for just this one bean definition by defining a factory-bean attribute on the HashMap bean, but which factory bean to use that won't call the FactoryBean post-processors is not something i could ferret out.


    Code:
       
    <bean id="fmSharedVars" name="appSharedVars" class="java.util.HashMap" >
       	<constructor-arg>
          <map key-type="java.lang.String" value-type="java.lang.String">
             <entry key="xml_escape" value-ref="fmXmlEscape"/>
            <entry key="_HOME_LINK_" >
    <value><![CDATA[<a href="/testAppl/HomeView.html?${User_Role}" title="Home"><span>Home</span></a>]]></value>
            </entry>
           </map>
      	</constructor-arg>
       </bean>
    
      <bean id="freeMarkerConfig" 
         class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
    
    <sniped other property elements>
    
       <property name="freemarkerVariables" ref="fmSharedVars" />
      </bean>

  2. #2
    Join Date
    May 2007
    Location
    Saint Petersburg, Russian Federation
    Posts
    1,189

    Default

    You can just change PropertyPlaceHolderConfigurer preffix/suffix. E.g. you can use %{...} instead of ${...}.

  3. #3
    Join Date
    Mar 2008
    Location
    SF Bay Area, California
    Posts
    11

    Default I could do that, but then all references to .properties files would have to change

    It occurred to me that was a possible hack, but then all the xml references to properties in my properties files would have to be changed to use %{xxx}.

    That did not seem an acceptable solution, but i may have to go that route.

    I was hoping for clean separation and a way to construct the Map bean without having to change anything else in my ApplicationContext*.xml files.

  4. #4
    Join Date
    May 2007
    Location
    Saint Petersburg, Russian Federation
    Posts
    1,189

    Default

    Quote Originally Posted by exAppl088 View Post
    It occurred to me that was a possible hack, but then all the xml references to properties in my properties files would have to be changed to use %{xxx}.

    That did not seem an acceptable solution, but i may have to go that route.

    I was hoping for clean separation and a way to construct the Map bean without having to change anything else in my ApplicationContext*.xml files.
    Well, you can simply implement your own BeanFactoryPostProcessor that works similarly to the PropertyPlaceholderConfigurer but doesn't perform substitution for injected values.

  5. #5
    Join Date
    Jul 2008
    Location
    Columbus, OH
    Posts
    43

    Default

    Quote Originally Posted by denis.zhdanov View Post
    Well, you can simply implement your own BeanFactoryPostProcessor that works similarly to the PropertyPlaceholderConfigurer but doesn't perform substitution for injected values.

    In addition, you could set the 'ignoreUnresolvePlaceholders' property of the PPHC to false:

    http://static.springframework.org/sp...olders(boolean)
    Thanks,
    Frank Lamantia

  6. #6
    Join Date
    Mar 2008
    Location
    SF Bay Area, California
    Posts
    11

    Question Either of these suggestions misses the main question!

    Yes, either of these solutions would work for the creation of the Map bean, but both ignore the main issue, what i want is to construct JUST the Map bean without placeholder substitution, WHILE leaving all the other beans created in the same ApplicationContext WITH placeholder substitution, and neither of these obvious changes would allow the other beans, which depend on property placeholder substitution, to be created.

    What would happen if i did create a custom PPHC or set the Ignore switch to true, is no substitutions would work on the other beans, or a runtime property NPE would be thrown for a property ref that was spelled wrong or some similar mistake, neither of which is an acceptable outcome.

    The solution i am looking for is how to have placeholder substitution disabled selectively for 1 specific bean while leaving it enabled for all the other beans, and i thought that my original post made that clear, but perhaps not

    Anyone have any idea if there is some way to acheive selective disable of placeholder substitution or can my 1 bean be created in a "parent" context that is only a "BeanFactory" context, with the ApplicationContext as a child?

    Will a web-app work properly setup in that manner?

    IF so, what has to be done in the deployment descriptor (web.xml) to create a parent BeanFactory context? (which would have no PPHC and could create the Map i need) I.E. How do you define two contexts and link a parent to a child and get them both loaded by the ContextListener in the web.xml.

    I am a newbie working on my first web-app, so any help will be much appreciated.

    I haven't found anything on how to create a context hierarchy in the Springs docs, but i suppose it is buried somewhere in Tomcat docs or some other older J2EE spec doc i need to locate?

  7. #7
    Join Date
    Mar 2008
    Location
    SF Bay Area, California
    Posts
    11

    Cool I found a post that answers how to create a parent-child context...

    This post shows how to create a parent-child context in the web.xml
    and i am going to see if i can create a parent-child setup with the
    Ignore Undefined Placeholders set to true in the parent where my Map
    will be created.

    This thread is from 2004 and it suggests that the info be added to the
    Spring Docs, but i guess that was never done! boooooyaaahhhh! .

    http://forum.springframework.org/showthread.php?t=14200
    Last edited by exAppl088; Mar 6th, 2009 at 12:12 PM. Reason: grammar fixed

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •