вторник, 30 августа 2016 г.

BeanCurrentlyInCreationException due to bug in spring boot

Run into a problem:
If project is built on Windows machine, it works perfectly.
If project is built on TeamCity CI Linux-agent, than on application startup I get the following exception:

org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'someBeanName': Requested bean is currently in creation: Is there an unresolvable circular reference?

It turned out that there is a bug in spring boot, which leads to this error - if using @ComponentScan on a large scope (e.g. main package of the project).

I had a @SpringBootApplication annotation on my main spring boot class, which also includes the @ComponentScan. Bug was gone after overriding it with specifying concrete packages:

@ComponentScan({"ru.thecop.config",
        "ru.thecop.service",
        "ru.thecop.controller"})

It seems that the order of packages in this annotation is important - if you still experiencing problems with startup/bean creations, a possible solution is to change order of packages in @ComponentScan.

Additional info on this problem can be found on Spring Boot Github and Jira Ticket.

Комментариев нет:

Отправить комментарий