Spring boot component scan include a single class

Anand Sunderraman picture Anand Sunderraman · Jun 11, 2016 · Viewed 9.4k times · Source

I am using spring component scan to auto detect beans as:

@ComponentScan({"com.org.x, com.org.y"})

The issue is I want all classes in com.org.x to be scanned but I want a single class, com.org.y.SomeService.class, alone to be scanned from com.org.y

How can I achieve this ?

Also apart from using context scan, how can I created this bean and inject in the application context ?

Answer

Lu55 picture Lu55 · May 25, 2018

@Import(com.org.y.SomeService.class) works in my case (even when SomeService is a @Service, not a @Configuration)