Return-Path: X-Original-To: apmail-cocoon-dev-archive@www.apache.org Delivered-To: apmail-cocoon-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 191499BA3 for ; Tue, 28 Feb 2012 21:00:40 +0000 (UTC) Received: (qmail 47849 invoked by uid 500); 28 Feb 2012 21:00:39 -0000 Delivered-To: apmail-cocoon-dev-archive@cocoon.apache.org Received: (qmail 47790 invoked by uid 500); 28 Feb 2012 21:00:39 -0000 Mailing-List: contact dev-help@cocoon.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@cocoon.apache.org List-Id: Delivered-To: mailing list dev@cocoon.apache.org Delivered-To: moderator for dev@cocoon.apache.org Received: (qmail 40575 invoked by uid 99); 28 Feb 2012 20:57:53 -0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of lgawron@gmail.com designates 74.125.83.51 as permitted sender) Received-SPF: pass (google.com: domain of lgawron@gmail.com designates 10.213.112.130 as permitted sender) client-ip=10.213.112.130; Authentication-Results: mr.google.com; spf=pass (google.com: domain of lgawron@gmail.com designates 10.213.112.130 as permitted sender) smtp.mail=lgawron@gmail.com; dkim=pass header.i=lgawron@gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; bh=OuqPmpWTiVEreVj8Zsu9rsE5gU21RMXA6cPrucemTbM=; b=j0/vX8c8OEiClQjK29EviZkjnXVA9vQrpHvzpmjXBn9Mg3GwX5ogqH18g5qxy70mTH 8K7HVQAXim/O7mmKivuUe9lW5ySneGawTZhkCMhS1sq3iMxyFSsr0cPtB01wsNMr8RO9 gLlS3/DJLI12gL8JZhh1qRKdKaQsYgd+cEu7g= Sender: Leszek Gawron Message-ID: <4F4D3FB2.4060200@mobilebox.pl> Date: Tue, 28 Feb 2012 21:57:22 +0100 From: Leszek Gawron User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 MIME-Version: 1.0 To: dev@cocoon.apache.org Subject: cocoon-spring-configurator issue Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Hello, I tried to upgrade my cocoon based product to use spring 3.0 new features. One of those is @Value("${propertyName}") annotation. This feature works for but does not for cocoon's . This is slightly weird as coocon configurator theoreticaly bases on PropertyPlaceholderConfigurer. The issue lies in this code (I used : cocoon-spring-configurator-1.0.2\src\main\java\org\apache\cocoon\spring\configurator\impl\AbstractSettingsBeanFactoryPostProcessor.java > /** > * @see org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#processProperties(org.springframework.beans.factory.config.ConfigurableListableBeanFactory, java.util.Properties) > */ > protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, > Properties props) > throws BeansException { > final BeanDefinitionVisitor visitor = new CocoonSettingsResolvingBeanDefinitionVisitor(this.settings); > String[] beanNames = beanFactoryToProcess.getBeanDefinitionNames(); > for (int i = 0; i < beanNames.length; i++) { > BeanDefinition bd = beanFactoryToProcess.getBeanDefinition(beanNames[i]); > try { > visitor.visitBeanDefinition(bd); > } catch (BeanDefinitionStoreException e) { > throw new BeanDefinitionStoreException(bd.getResourceDescription(), beanNames[i], e); > } > } > } > protected class CocoonSettingsResolvingBeanDefinitionVisitor extends BeanDefinitionVisitor { > > protected final Properties props; > protected final Set visitedPlaceholders = new HashSet(); > > public CocoonSettingsResolvingBeanDefinitionVisitor( Settings settings ) { > this.props = new SettingsProperties( settings ); > } > > protected String resolveStringValue( String strVal ) { > return parseStringValue( strVal, > this.props, > visitedPlaceholders ); > } > } This method completely rewrites the super method (from PropertyPlaceholderConfigurer) which looks like this: > @Override > protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) > throws BeansException { > > StringValueResolver valueResolver = new PlaceholderResolvingStringValueResolver(props); > BeanDefinitionVisitor visitor = new BeanDefinitionVisitor(valueResolver); > > String[] beanNames = beanFactoryToProcess.getBeanDefinitionNames(); > for (String curName : beanNames) { > // Check that we're not parsing our own bean definition, > // to avoid failing on unresolvable placeholders in properties file locations. > if (!(curName.equals(this.beanName) && beanFactoryToProcess.equals(this.beanFactory))) { > BeanDefinition bd = beanFactoryToProcess.getBeanDefinition(curName); > try { > visitor.visitBeanDefinition(bd); > } > catch (Exception ex) { > throw new BeanDefinitionStoreException(bd.getResourceDescription(), curName, ex.getMessage()); > } > } > } > > // New in Spring 2.5: resolve placeholders in alias target names and aliases as well. > beanFactoryToProcess.resolveAliases(valueResolver); > > // New in Spring 3.0: resolve placeholders in embedded values such as annotation attributes. > beanFactoryToProcess.addEmbeddedValueResolver(valueResolver); > } As you see new features completely got disabled. What I actually did was the easiest solution of all: > /** > * @see org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#processProperties(org.springframework.beans.factory.config.ConfigurableListableBeanFactory, > * java.util.Properties) > */ > protected void processProperties( ConfigurableListableBeanFactory beanFactoryToProcess, Properties props ) throws BeansException { > super.processProperties( beanFactoryToProcess, > new SettingsProperties( this.settings ) ); > } and @Value works as expected. Still I am not aware if the original solution was a mistake or was thought out for some other use case. If noone objects I'd like to commit my change. -- Leszek Gawron http://www.mobilebox.pl/krs.html CTO at MobileBox S.A.