Класс PersonController находится внутри модуля external (этот модуль также имеет зависимость) – аннотации @RestControllerВ моем модуле Application я создаю экземпляры bean-компонентов как таковые и ожидаю, что PersonController из пользовательской зависимости не будет включен. Как видите, компонентComponentScan необходим для других классов, которые я использую из пользовательской зависимости
Код: Выделить всё
@Configuration
@ComponentScan(
basePackages = "xl.person",
excludeFilters={
@ComponentScan.Filter(
type = FilterType.ASSIGNABLE_TYPE,
value = { xl.person.controller.PersonController.class }
)
}
)
public class PersonConfiguration {
@Bean
@Primary
PersonController personController(
PersonService service, //from dependency
PersonSecondService serviceTwo //not from dependency
) {
return new PersonController(service, serviceTwo);
}
}
Код: Выделить всё
@SpringBootApplication(
scanBasePackages = "xl.app"
exclude = { PersonController.class }
)
Код: Выделить всё
//Annotation-specified bean name 'personController' for bean class [xl.person.controller.PersonController] conflicts with existing, non-compatible bean definition of same name and class [xl.app.external.PersonController]
Похоже, что триггером является @RestController в моем определении PersonController. Таким образом, во внешнем модуле класс уже создан, а затем конфликтует с пользовательской зависимостью. Однако по очевидным причинам я хочу сохранить @RestController в своем классе контроллера.
Подробнее здесь: https://stackoverflow.com/questions/793 ... dependency
Мобильная версия