marcingrzejszczak commented on code in PR #1346:
URL: https://github.com/apache/cxf/pull/1346#discussion_r1290014179


##########
integration/spring-boot/autoconfigure/src/main/java/org/apache/cxf/spring/boot/autoconfigure/micrometer/MicrometerObservationAutoConfiguration.java:
##########
@@ -0,0 +1,58 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.spring.boot.autoconfigure.micrometer;
+
+import org.apache.cxf.tracing.micrometer.MessageInObservationConvention;
+import org.apache.cxf.tracing.micrometer.MessageOutObservationConvention;
+import org.apache.cxf.tracing.micrometer.ObservationClientFeature;
+import org.apache.cxf.tracing.micrometer.ObservationFeature;
+import org.springframework.beans.factory.ObjectProvider;
+import 
org.springframework.boot.actuate.autoconfigure.observation.ObservationAutoConfiguration;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import 
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import io.micrometer.observation.ObservationRegistry;
+
+@Configuration
+@AutoConfigureAfter(ObservationAutoConfiguration.class)
+@ConditionalOnClass({ ObservationRegistry.class, ObservationFeature.class })
+@ConditionalOnProperty(name = "cxf.observation.enabled", matchIfMissing = true)
+@ConditionalOnBean(ObservationRegistry.class)
+public class MicrometerObservationAutoConfiguration {

Review Comment:
   Oh be my guest :) 
   
   What I did is I modified the `JAXRSServerFactoryBeanDefinitionParser` to 
have its last static method to fallback to constructor autowiring.
   
   ```java
   static List<Object> createBeansFromDiscoveredClasses(ApplicationContext 
context,
                                                            
Collection<Class<?>> classes,
                                                            Class<? extends 
Annotation> serviceClassAnnotation) {
           AutowireCapableBeanFactory beanFactory = 
context.getAutowireCapableBeanFactory();
           final List< Object > providers = new ArrayList<>();
           for (final Class< ? > clazz: classes) {
               if (serviceClassAnnotation != null && 
clazz.getAnnotation(serviceClassAnnotation) == null) {
                   continue;
               }
               Object bean;
               try {
                   bean = beanFactory.createBean(clazz, 
AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
               } catch (Exception ex) {
                   String stackTrace = ExceptionUtils.getStackTrace(ex);
                   LOG.fine("Autowire failure for a " + clazz.getName() + " 
bean: " + stackTrace);
                   try {
                       bean = beanFactory.createBean(clazz);
                   } catch (Exception ex2) {
                       // Fallback to constructor based injection
                       String stackTrace2 = ExceptionUtils.getStackTrace(ex2);
                       LOG.fine("Bean creation failure for a " + 
clazz.getName() + " bean: " + stackTrace2);
                       GenericBeanDefinition definition = new 
GenericBeanDefinition();
                       definition.setBeanClass(clazz);
                       
definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR);
                       String name = clazz.getName() + "_" + 
System.currentTimeMillis();
                       ((BeanDefinitionRegistry) 
context).registerBeanDefinition(name, definition);
                       bean = context.getBean(name);
                   }
               }
               providers.add(bean);
           }
           return providers;
       }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@cxf.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to