cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1548494 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/JAXRSServerFactoryBeanDefinitionParser.java systests/jaxrs/src/test/resources/jaxrs_spring_discovery/WEB-INF/beans.xml
Date Fri, 06 Dec 2013 11:15:57 GMT
Author: sergeyb
Date: Fri Dec  6 11:15:57 2013
New Revision: 1548494

URL: http://svn.apache.org/r1548494
Log:
[CXF-3725] Optional autodiscovery of JAX-RS root resources, patch from Andriy Redko applied

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/JAXRSServerFactoryBeanDefinitionParser.java
    cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_discovery/WEB-INF/beans.xml

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/JAXRSServerFactoryBeanDefinitionParser.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/JAXRSServerFactoryBeanDefinitionParser.java?rev=1548494&r1=1548493&r2=1548494&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/JAXRSServerFactoryBeanDefinitionParser.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/JAXRSServerFactoryBeanDefinitionParser.java
Fri Dec  6 11:15:57 2013
@@ -25,6 +25,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import javax.ws.rs.Path;
 import javax.ws.rs.ext.Provider;
 import javax.xml.namespace.QName;
 
@@ -205,6 +206,7 @@ public class JAXRSServerFactoryBeanDefin
             try {
                 if (basePackages != null && !basePackages.isEmpty()) {
                     final List< Object > providers = new ArrayList< Object >();
+                    final List< Object > services = new ArrayList< Object >();
                     
                     // Reusing Spring's approach to classpath scanning. Because Java packages
are
                     // open, it's impossible to get all classes belonging to specific package.
@@ -231,8 +233,9 @@ public class JAXRSServerFactoryBeanDefin
                             
                             // Create a bean only if it's a provider (annotated)
                             if (metadata.isAnnotated(Provider.class.getName())) {       
                        
-                                final Class<?> clazz = ClassLoaderUtils.loadClass(metadata.getClassName(),
getClass());
-                                providers.add(ctx.getAutowireCapableBeanFactory().createBean(clazz));
+                                providers.add(createBean(ctx, metadata));
+                            } else if (metadata.isAnnotated(Path.class.getName())) { 
+                                services.add(createBean(ctx, metadata));
                             }
                         }                        
                     }
@@ -240,6 +243,10 @@ public class JAXRSServerFactoryBeanDefin
                     if (!providers.isEmpty()) {                        
                         this.setProviders(providers);
                     }
+                    
+                    if (!services.isEmpty()) {                        
+                        this.setServiceBeans(services);
+                    }
                 }
             } catch (IOException ex) {
                 throw new BeanDefinitionStoreException("I/O failure during classpath scanning",
ex);
@@ -251,6 +258,12 @@ public class JAXRSServerFactoryBeanDefin
                 setBus(BusWiringBeanFactoryPostProcessor.addDefaultBus(ctx));
             }
         }
+
+        private Object createBean(final ApplicationContext ctx, final AnnotationMetadata
metadata) 
+            throws ClassNotFoundException {
+            final Class<?> clazz = ClassLoaderUtils.loadClass(metadata.getClassName(),
getClass());
+            return ctx.getAutowireCapableBeanFactory().createBean(clazz);
+        }
         
         private boolean shouldSkip(final String classname) {
             return classname.startsWith("org.apache.cxf");

Modified: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_discovery/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_discovery/WEB-INF/beans.xml?rev=1548494&r1=1548493&r2=1548494&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_discovery/WEB-INF/beans.xml (original)
+++ cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_discovery/WEB-INF/beans.xml Fri
Dec  6 11:15:57 2013
@@ -28,12 +28,5 @@ http://cxf.apache.org/schemas/jaxrs.xsd"
 	<import resource="classpath:/META-INF/cxf/cxf.xml"/>
 	<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
 
-    <jaxrs:server address="/" base-packages="org.apache.cxf.jaxrs.validation">
-        <jaxrs:serviceBeans>
-            <ref bean="bookStore"/>
-        </jaxrs:serviceBeans>
-    </jaxrs:server>
-    
-    <bean id="bookStore" class="org.apache.cxf.systest.jaxrs.discovery.BookStore" />
-    
+    <jaxrs:server address="/" base-packages="org.apache.cxf.jaxrs.validation, org.apache.cxf.systest.jaxrs.discovery"
/>
 </beans>



Mime
View raw message