You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2011/10/17 19:58:36 UTC

svn commit: r1185310 - in /tapestry/tapestry5/trunk: tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/ tapestry-spring/src/main/java/org/apache/tapestry5/internal/spring/ tapestry-spring/src/main/java/org/apache/tapestry5/spring/ tapestry-s...

Author: hlship
Date: Mon Oct 17 17:58:36 2011
New Revision: 1185310

URL: http://svn.apache.org/viewvc?rev=1185310&view=rev
Log:
TAP5-1693: Spring beans of type java.lang.String can confuse Tapestry, which will use them in preference to other injections, such as @Symbol

Modified:
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java
    tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry5/internal/spring/SpringModuleDef.java
    tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry5/spring/SpringConstants.java
    tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry5/spring/SpringModule.java
    tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/WEB-INF/applicationContext.xml

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java?rev=1185310&r1=1185309&r2=1185310&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java Mon Oct 17 17:58:36 2011
@@ -111,8 +111,8 @@ public final class TapestryIOCModule
     /**
      * <dl>
      * <dt>AnnotationBasedContributions</dt>
-     * <dd>Empty placeholder used to seperate annotation-based ObjectProvider contributions (which come before) from
-     * non-annotation based (ServiceOverride here, Alias in tapestry-core) which come after.</dd>
+     * <dd>Empty placeholder used to separate annotation-based ObjectProvider contributions (which come before) from
+     * non-annotation based (such as ServiceOverride) which come after.</dd>
      * <dt>Value</dt>
      * <dd>Supports the {@link org.apache.tapestry5.ioc.annotations.Value} annotation</dd>
      * <dt>Symbol</dt>

Modified: tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry5/internal/spring/SpringModuleDef.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry5/internal/spring/SpringModuleDef.java?rev=1185310&r1=1185309&r2=1185310&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry5/internal/spring/SpringModuleDef.java (original)
+++ tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry5/internal/spring/SpringModuleDef.java Mon Oct 17 17:58:36 2011
@@ -25,7 +25,6 @@ import org.apache.tapestry5.ioc.internal
 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
 import org.apache.tapestry5.ioc.services.ClassFabUtils;
 import org.apache.tapestry5.ioc.services.RegistryShutdownHub;
-import org.apache.tapestry5.ioc.services.RegistryShutdownListener;
 import org.apache.tapestry5.spring.ApplicationContextCustomizer;
 import org.apache.tapestry5.spring.SpringConstants;
 import org.springframework.beans.factory.BeanFactoryUtils;
@@ -70,12 +69,10 @@ public class SpringModuleDef implements 
      * Invoked to obtain the Spring ApplicationContext, presumably stored in the ServletContext.
      * This method is only used in Tapestry 5.0 compatibility mode (in Tapestry 5.1 and above,
      * the default is for Tapestry to <em>create</em> the ApplicationContext).
-     * 
-     * @param servletContext
-     *            used to locate the ApplicationContext
+     *
+     * @param servletContext used to locate the ApplicationContext
      * @return the ApplicationContext itself
-     * @throws RuntimeException
-     *             if the ApplicationContext could not be located or is otherwise invalid
+     * @throws RuntimeException if the ApplicationContext could not be located or is otherwise invalid
      * @since 5.2.0
      */
     protected ApplicationContext locateApplicationContext(ServletContext servletContext)
@@ -163,7 +160,7 @@ public class SpringModuleDef implements 
 
     private ObjectCreator constructObjectCreatorForApplicationContext(
             final ServiceBuilderResources resources, @Primary
-            ApplicationContextCustomizer customizer)
+    ApplicationContextCustomizer customizer)
     {
         final CustomizingContextLoader loader = new CustomizingContextLoader(customizer);
 
@@ -240,7 +237,7 @@ public class SpringModuleDef implements 
 
             @Override
             public void contribute(ModuleBuilderSource moduleSource, ServiceResources resources,
-                    OrderedConfiguration configuration)
+                                   OrderedConfiguration configuration)
             {
                 final OperationTracker tracker = resources.getTracker();
 
@@ -250,7 +247,7 @@ public class SpringModuleDef implements 
                 final ObjectProvider springBeanProvider = new ObjectProvider()
                 {
                     public <T> T provide(Class<T> objectType,
-                            AnnotationProvider annotationProvider, ObjectLocator locator)
+                                         AnnotationProvider annotationProvider, ObjectLocator locator)
                     {
 
                         Map beanMap = context.getBeansOfType(objectType);
@@ -272,8 +269,8 @@ public class SpringModuleDef implements 
                                         .format(
                                                 "Spring context contains %d beans assignable to type %s: %s.",
                                                 beanMap.size(), ClassFabUtils
-                                                        .toJavaClassName(objectType), InternalUtils
-                                                        .joinSorted(beanMap.keySet()));
+                                                .toJavaClassName(objectType), InternalUtils
+                                                .joinSorted(beanMap.keySet()));
 
                                 throw new IllegalArgumentException(message);
                         }
@@ -283,7 +280,7 @@ public class SpringModuleDef implements 
                 final ObjectProvider springBeanProviderInvoker = new ObjectProvider()
                 {
                     public <T> T provide(final Class<T> objectType,
-                            final AnnotationProvider annotationProvider, final ObjectLocator locator)
+                                         final AnnotationProvider annotationProvider, final ObjectLocator locator)
                     {
                         return tracker.invoke(
                                 "Resolving dependency by searching Spring ApplicationContext",
@@ -301,7 +298,7 @@ public class SpringModuleDef implements 
                 ObjectProvider outerCheck = new ObjectProvider()
                 {
                     public <T> T provide(Class<T> objectType,
-                            AnnotationProvider annotationProvider, ObjectLocator locator)
+                                         AnnotationProvider annotationProvider, ObjectLocator locator)
                     {
                         // I think the following line is the only reason we put the
                         // SpringBeanProvider here,
@@ -315,7 +312,8 @@ public class SpringModuleDef implements 
                     }
                 };
 
-                configuration.add("SpringBean", outerCheck, "after:Service,Alias,Autobuild");
+
+                configuration.add("SpringBean", outerCheck, "after:AnnotationBasedContributions", "after:ServiceOverride");
             }
         };
 

Modified: tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry5/spring/SpringConstants.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry5/spring/SpringConstants.java?rev=1185310&r1=1185309&r2=1185310&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry5/spring/SpringConstants.java (original)
+++ tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry5/spring/SpringConstants.java Mon Oct 17 17:58:36 2011
@@ -1,4 +1,4 @@
-// Copyright 2009 The Apache Software Foundation
+// Copyright 2009, 2011 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -24,7 +24,7 @@ public class SpringConstants
     /**
      * If true, then Tapestry will attempt to use an externally configured Spring ApplicationContext rather than create
      * its own. This will disable the ability to inject Tapestry IoC services and objects into Spring beans. This
-     * <em>must</em> be configured as a conetxt &lt;init-parameter&gt; in web.xml.
+     * <em>must</em> be configured as a context &lt;init-parameter&gt; in web.xml.
      */
     public static final String USE_EXTERNAL_SPRING_CONTEXT = "tapestry.use-external-spring-context";
 }

Modified: tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry5/spring/SpringModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry5/spring/SpringModule.java?rev=1185310&r1=1185309&r2=1185310&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry5/spring/SpringModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry5/spring/SpringModule.java Mon Oct 17 17:58:36 2011
@@ -1,4 +1,4 @@
-// Copyright 2008, 2009 The Apache Software Foundation
+// Copyright 2008, 2009, 2011 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -14,16 +14,15 @@
 
 package org.apache.tapestry5.spring;
 
-import java.util.List;
-
-import javax.servlet.ServletContext;
-
 import org.apache.tapestry5.internal.spring.SymbolBeanFactoryPostProcessor;
 import org.apache.tapestry5.ioc.MappedConfiguration;
 import org.apache.tapestry5.ioc.OrderedConfiguration;
+import org.apache.tapestry5.ioc.annotations.Contribute;
 import org.apache.tapestry5.ioc.annotations.Marker;
 import org.apache.tapestry5.ioc.annotations.Primary;
 import org.apache.tapestry5.ioc.services.ChainBuilder;
+import org.apache.tapestry5.ioc.services.FactoryDefaults;
+import org.apache.tapestry5.ioc.services.SymbolProvider;
 import org.apache.tapestry5.ioc.services.SymbolSource;
 import org.apache.tapestry5.services.ApplicationInitializer;
 import org.apache.tapestry5.services.ApplicationInitializerFilter;
@@ -33,6 +32,9 @@ import org.springframework.context.Appli
 import org.springframework.core.SpringVersion;
 import org.springframework.web.context.ConfigurableWebApplicationContext;
 
+import javax.servlet.ServletContext;
+import java.util.List;
+
 /**
  * Module for Tapestry/Spring Integration. This module exists to force the load of the Spring ApplicationContext as part
  * of Tapestry application initialization.
@@ -48,7 +50,8 @@ public class SpringModule
         this.logger = logger;
     }
 
-    public void contributeApplicationInitializer(
+    @Contribute(ApplicationInitializer.class)
+    public void reportSpringContextDetailsAtStartup(
             OrderedConfiguration<ApplicationInitializerFilter> configuration, final ApplicationContext springContext)
     {
         ApplicationInitializerFilter filter = new ApplicationInitializerFilter()
@@ -56,8 +59,8 @@ public class SpringModule
             public void initializeApplication(Context context, ApplicationInitializer initializer)
             {
                 logger.info(String.format("Spring version %s with %,d defined beans.",
-                                          SpringVersion.getVersion(),
-                                          springContext.getBeanDefinitionCount()));
+                        SpringVersion.getVersion(),
+                        springContext.getBeanDefinitionCount()));
 
                 initializer.initializeApplication(context);
             }
@@ -66,9 +69,11 @@ public class SpringModule
         configuration.add("SpringContextInitialization", filter);
     }
 
-    public static void contributeFactoryDefaults(MappedConfiguration<String, String> configuration)
+    @Contribute(SymbolProvider.class)
+    @FactoryDefaults
+    public static void defaultExternalSpringContextOff(MappedConfiguration<String, Object> configuration)
     {
-        configuration.add(SpringConstants.USE_EXTERNAL_SPRING_CONTEXT, "false");
+        configuration.add(SpringConstants.USE_EXTERNAL_SPRING_CONTEXT, false);
     }
 
     /**
@@ -83,22 +88,23 @@ public class SpringModule
     {
         return builder.build(ApplicationContextCustomizer.class, configuration);
     }
-    
-    public static void contributeApplicationContextCustomizer(
-            OrderedConfiguration<ApplicationContextCustomizer> configuration, 
+
+    @Contribute(ApplicationContextCustomizer.class)
+    public static void addSymbolSourceAsPropertyCustomizerForSpringBeans(
+            OrderedConfiguration<ApplicationContextCustomizer> configuration,
             final SymbolSource symbolSource)
     {
         ApplicationContextCustomizer beanFactoryPostProcessorCustomizer = new ApplicationContextCustomizer()
         {
-            
+
             public void customizeApplicationContext(ServletContext servletContext,
-                    ConfigurableWebApplicationContext applicationContext)
+                                                    ConfigurableWebApplicationContext applicationContext)
             {
                 applicationContext.addBeanFactoryPostProcessor(new SymbolBeanFactoryPostProcessor(symbolSource));
-                
+
             }
         };
-        
+
         configuration.add("BeanFactoryPostProcessorCustomizer", beanFactoryPostProcessorCustomizer);
     }
 }

Modified: tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/WEB-INF/applicationContext.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/WEB-INF/applicationContext.xml?rev=1185310&r1=1185309&r2=1185310&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/WEB-INF/applicationContext.xml (original)
+++ tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/WEB-INF/applicationContext.xml Mon Oct 17 17:58:36 2011
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!-- 
-   Copyright 2007, 2008 The Apache Software Foundation
+   Copyright 2007, 2008, 2011 The Apache Software Foundation
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -32,16 +32,24 @@
     <bean id="barney" class="org.example.testapp.services.FlintstoneImpl"/>
 
     <bean id="viaFactory" class="org.example.testapp.services.ViaFactoryFactory"/>
-    
-   	<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
-    	<property name="properties">
-        	<value>value.from.spring=Hello</value>
-    	</property>
-	</bean>
+
+    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
+        <property name="properties">
+            <value>value.from.spring=Hello</value>
+        </property>
+    </bean>
 
     <bean id="symbolValueHolder" class="org.example.testapp.services.SymbolValueHolder">
-    	<property name="value" value="${tapestry.start-page-name}"/>
-    	<property name="anotherValue" value="${value.from.spring}"/>
+        <property name="value" value="${tapestry.start-page-name}"/>
+        <property name="anotherValue" value="${value.from.spring}"/>
+    </bean>
+
+    <!-- In TAP5-1693, a user has a Spring bean that's a string configured to ultimately
+         be used in a JNDI lookup. -->
+    <bean id="TAP5-1693" class="java.lang.String">
+        <constructor-arg>
+            <value>This is just a string.</value>
+        </constructor-arg>
     </bean>
 
 </beans>