snicoll commented on a change in pull request #6: Rationalise use of 
ObjectMapper
URL: https://github.com/apache/rocketmq-spring/pull/6#discussion_r242068630
 
 

 ##########
 File path: 
rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/config/RocketMQAutoConfiguration.java
 ##########
 @@ -18,30 +18,37 @@
 package org.apache.rocketmq.spring.config;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.rocketmq.client.MQAdmin;
 import org.apache.rocketmq.client.producer.DefaultMQProducer;
 import org.apache.rocketmq.spring.core.RocketMQTemplate;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.beans.factory.config.BeanDefinition;
+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.boot.autoconfigure.jackson.JacksonAutoConfiguration;
 import 
org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Import;
 import org.springframework.context.annotation.Role;
 import org.springframework.util.Assert;
 
-import java.util.Objects;
-
 @Configuration
 @EnableConfigurationProperties(RocketMQProperties.class)
+@ConditionalOnClass({ MQAdmin.class, ObjectMapper.class })
 @ConditionalOnProperty(prefix = "spring.rocketmq", value = "name-server")
 @Import(ListenerContainerConfiguration.class)
+@AutoConfigureAfter(JacksonAutoConfiguration.class)
 public class RocketMQAutoConfiguration {
 
+    @Bean
+    @ConditionalOnMissingBean(ObjectMapper.class)
 
 Review comment:
   I think it vastly depends what you want to do as part of the starter and it 
it still unclear to me. If you want to use the "object mapper" defined in the 
context, then relying on a named bean by default is the wrong thing to do (as 
you'd force user to name their unique instance that way).
   
   If you want to make sure that a dedicated `ObjectMapper` is used for 
rocketmq, then it should be more clear than just the name. 
   
   The suggestion here is the best compromise: if you have a single instance 
we'll use that. If you have more than one, we'll look for the `@Primary` one 
and if that does not exist we'll fallback to one named 
`rocketMQMessageObjectMapper`.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to