You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by jk...@apache.org on 2016/02/16 12:06:54 UTC

tapestry-5 git commit: TAP5-1837: NPE on registry startup when using tapestry.use-external-spring-context

Repository: tapestry-5
Updated Branches:
  refs/heads/master 2dd5bb525 -> 3c0b3b3f7


TAP5-1837: NPE on registry startup when using tapestry.use-external-spring-context


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/3c0b3b3f
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/3c0b3b3f
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/3c0b3b3f

Branch: refs/heads/master
Commit: 3c0b3b3f7859bb334cd256d0bd8d57564c59b6df
Parents: 2dd5bb5
Author: Matthias Nöbl <ma...@cropster.com>
Authored: Mon Feb 15 16:14:15 2016 +0100
Committer: Jochen Kemnade <jo...@eddyson.de>
Committed: Tue Feb 16 12:06:10 2016 +0100

----------------------------------------------------------------------
 .../internal/spring/SpringModuleDef.java        | 22 +++++++++++++++++---
 .../internal/spring/SpringModuleDefTest.java    | 21 ++++++++++++++++++-
 2 files changed, 39 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/3c0b3b3f/tapestry-spring/src/main/java/org/apache/tapestry5/internal/spring/SpringModuleDef.java
----------------------------------------------------------------------
diff --git a/tapestry-spring/src/main/java/org/apache/tapestry5/internal/spring/SpringModuleDef.java b/tapestry-spring/src/main/java/org/apache/tapestry5/internal/spring/SpringModuleDef.java
index efd706c..734f7f2 100644
--- a/tapestry-spring/src/main/java/org/apache/tapestry5/internal/spring/SpringModuleDef.java
+++ b/tapestry-spring/src/main/java/org/apache/tapestry5/internal/spring/SpringModuleDef.java
@@ -27,8 +27,9 @@ import org.apache.tapestry5.ioc.services.RegistryShutdownHub;
 import org.apache.tapestry5.plastic.PlasticUtils;
 import org.apache.tapestry5.spring.ApplicationContextCustomizer;
 import org.apache.tapestry5.spring.SpringConstants;
-import org.springframework.beans.factory.BeanFactoryUtils;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
 import org.springframework.context.ApplicationContext;
+import org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.core.SpringVersion;
 import org.springframework.web.context.ConfigurableWebApplicationContext;
 import org.springframework.web.context.WebApplicationContext;
@@ -159,11 +160,26 @@ public class SpringModuleDef implements ModuleDef
 
     private void addServiceDefsForSpringBeans(ApplicationContext context)
     {
+        ConfigurableListableBeanFactory beanFactory = null;
+        if (context instanceof ConfigurableApplicationContext)
+        {
+            beanFactory = ((ConfigurableApplicationContext) context).getBeanFactory();
+        }
+
         for (final String beanName : context.getBeanDefinitionNames())
         {
-            String trueName = beanName.startsWith("&") ? beanName.substring(1) : beanName;
+            boolean isAbstract = false;
+            if (beanFactory != null)
+            {
+                isAbstract = beanFactory.getBeanDefinition(beanName).isAbstract();
+            }
+
+            if (!isAbstract)
+            {
+                String trueName = beanName.startsWith("&") ? beanName.substring(1) : beanName;
 
-            services.put(trueName, new SpringBeanServiceDef(trueName, context));
+                services.put(trueName, new SpringBeanServiceDef(trueName, context));
+            }
         }
     }
 

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/3c0b3b3f/tapestry-spring/src/test/java/org/apache/tapestry5/internal/spring/SpringModuleDefTest.java
----------------------------------------------------------------------
diff --git a/tapestry-spring/src/test/java/org/apache/tapestry5/internal/spring/SpringModuleDefTest.java b/tapestry-spring/src/test/java/org/apache/tapestry5/internal/spring/SpringModuleDefTest.java
index b7dea62..2016fe9 100644
--- a/tapestry-spring/src/test/java/org/apache/tapestry5/internal/spring/SpringModuleDefTest.java
+++ b/tapestry-spring/src/test/java/org/apache/tapestry5/internal/spring/SpringModuleDefTest.java
@@ -20,6 +20,8 @@ import org.apache.tapestry5.ioc.ServiceBuilderResources;
 import org.apache.tapestry5.ioc.def.ServiceDef;
 import org.apache.tapestry5.spring.SpringConstants;
 import org.apache.tapestry5.spring.SpringTestCase;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
 import org.springframework.web.context.ConfigurableWebApplicationContext;
 import org.springframework.web.context.WebApplicationContext;
 import org.testng.annotations.Test;
@@ -32,16 +34,31 @@ public class SpringModuleDefTest extends SpringTestCase
     public void load_application_context_externally()
     {
         ServletContext servletContext = mockServletContext();
+        ConfigurableListableBeanFactory beanFactory = newMock(
+                ConfigurableListableBeanFactory.class);
         ConfigurableWebApplicationContext ac = newMock(ConfigurableWebApplicationContext.class);
         Runnable fred = mockRunnable();
         Runnable barney = mockRunnable();
+        Runnable arnold = mockRunnable();
+        BeanDefinition fredBeanDef = newMock(BeanDefinition.class);
+        BeanDefinition barneyBeanDef = newMock(BeanDefinition.class);
+        BeanDefinition arnoldBeanDef = newMock(BeanDefinition.class);
 
         ServiceBuilderResources resources = mockServiceBuilderResources();
 
         train_getInitParameter(servletContext, SpringConstants.USE_EXTERNAL_SPRING_CONTEXT, "true");
 
         train_getAttribute(servletContext, WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ac);
-        expect(ac.getBeanDefinitionNames()).andReturn(new String[] {"fred", "&barney"});
+        expect(ac.getBeanFactory()).andReturn(beanFactory);
+        expect(ac.getBeanDefinitionNames()).andReturn(new String[] { "fred", "&barney", "arnold" });
+
+        expect(fredBeanDef.isAbstract()).andReturn(false);
+        expect(barneyBeanDef.isAbstract()).andReturn(false);
+        expect(arnoldBeanDef.isAbstract()).andReturn(true);
+
+        expect(beanFactory.getBeanDefinition("fred")).andReturn(fredBeanDef);
+        expect(beanFactory.getBeanDefinition("&barney")).andReturn(barneyBeanDef);
+        expect(beanFactory.getBeanDefinition("arnold")).andReturn(arnoldBeanDef);
 
         replay();
 
@@ -89,6 +106,8 @@ public class SpringModuleDefTest extends SpringTestCase
         sd = moduleDef.getServiceDef("barney");
 
         assertSame(sd.createServiceCreator(null).createObject(), barney);
+
+        assertNull(moduleDef.getServiceDef("arnold"));
     }
 
     @Test