![]() ![]() The declaration of the missing bean was just below the declaration of ProcessExecutor bean. It looked as if Spring could not find the right ObjectMapper to inject into our ProcessExecutor! We were confused at first. Bean method 'jacksonObjectMapper' not loaded because did not find required class '.json.Jackson2ObjectMapperBuilder'Ĭonsider revisiting the conditions above or defining a bean of type '.ObjectMapper' in your configuration. Parameter 1 of method processExecutor in required a bean of type '.ObjectMapper' that could not be found. To display the auto-configuration report re-run your application with 'debug' enabled. Dependency annotations: 17:46:55.615 INFO 16382 - utoConfigurationReportLoggingInitializer :Įrror starting ApplicationContext. 17:46:55.608 WARN 16382 - s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: .UnsatisfiedDependencyException: Error creating bean with name 'processExecutor' defined in class path resource : Unsatisfied dependency expressed through method 'processExecutor' parameter 1 nested exception is .NoSuchBeanDefinitionException: No qualifying bean of type '.ObjectMapper' available: expected at least 1 bean which qualifies as autowire candidate. ![]() 17:46:55.175 INFO 16382 - o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'objectMapper' with a different definition: replacing scope= abstract=false lazyInit=false autowireMode=3 dependenc圜heck=0 autowireCandidate=true primary=false factoryBeanName=processExecutorConfig factoryMethodName=objectMapper initMethodName=null destroyMethodName=(inferred) defined in class path resource ] with scope= abstract=false lazyInit=false autowireMode=3 dependenc圜heck=0 autowireCandidate=true primary=false factoryBeanName=externalApiClientConfig factoryMethodName=objectMapper initMethodName=null destroyMethodName=(inferred) defined in class path resource ] 17:46:54.727 INFO 16382 - s.c.a.AnnotationConfigApplicationContext : Refreshing startup date root of context hierarchy 17:46:54.627 INFO 16382 - : No active profile set, falling back to default profiles: default 17:46:54.624 INFO 16382 - : Starting App on mfedkowicz-Vostro-5568 with PID 16382 (/home/mfedkowicz/tratif/bean-overriding/process-executor/target/classes started by mfedkowicz in /home/mfedkowicz/tratif/bean-overriding) As the result, our whole configuration consisted of classes similar to the ones presented below: ![]() Knowing that we will have two beans of the same type (two ObjectMappers) we had annotated them with annotation to inject proper instances into desired services. Of course the external-api-client module configuration was supposed to be imported into the configuration class of process-executor. We store it for audit purposes and also because sometimes we have to send the same request again. This second mapper had to have a bit different configuration and was supposed to serialize data which we save in our database. What is crucial is that its configuration contained second bean of type ObjectMapper. The second module we implemented was process-executor, which was responsible for executing processes for this particular client. Let’s say this first module was called external-api-client. Because the message format was JSON, the configuration class for the REST client module contained declaration of a customized ObjectMapper bean from Jackson library. The first thing we did was writing a client to introduce a layer of abstraction over the external API. In our case we were responsible for implementing integration with a new client, which provided REST API for its services. It seemed at first as if one of our beans had somehow disappeared. We were not aware of it and it had caused us a bit of confusion lately. Today I would like to tell you about one mechanism of Spring IoC container that I think is a bit less known amongst programmers. With such amount of code and numerous pages of documentation as Spring framework has, it is virtually impossible to know them all. Let’s face it – there are features of Spring that many of us probably do not know about. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |