Spring Boot ConflictingBeanDefinitionException: Annotation-specified bean name for @Controller class
I ran into the same problem but for a different reason.
This can also occur if you move your classes around in your project and fail to do a 'clean'.
I use gradle with spring-boot plugin. Now I usually run:
$> ./gradlew clean bootRun
The solution, as I found out, is to disable double initialization by including a filter in the component scan. In my case:
@EnableScheduling
@EnableAspectJAutoProxy
@EnableCaching
@Configuration
@ComponentScan(basePackages = { "org.kemri.wellcome.hie" },
excludeFilters = {@Filter(value = Controller.class, type = FilterType.ANNOTATION)})
@EnableAutoConfiguration
@PropertySource("classpath:application.properties")
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
I had the same problem on a Spring integration test when I ran it with InteliJ.
After a refactor, one of my controller class was actually duplicate in the /out/production/classes directory which is the default output directory for Intelij since version 2017.2. Since the gradle output directory is different (It's build/classes), the gradle clean goal had no effect.
For me the solution was to manually remove /out/production/classes and re run my integration test.
For a possible durable solution not having 2 output directories see here