Questions regarding using `@ComponentScan` to detect Spring managed components
Questions tagged [component-scan]
129 questions
195
votes
8 answers
multiple packages in context:component-scan, spring config
How can I add multiple packages in spring-servlet.xml file in context:component-scan element?
I have tried
and

Shams
- 3,637
- 5
- 31
- 49
58
votes
2 answers
getServletConfigClasses() vs getRootConfigClasses() when extending AbstractAnnotationConfigDispatcherServletInitializer
What is the difference between getServletConfigClasses() vs getRootConfigClasses() when extending AbstractAnnotationConfigDispatcherServletInitializer.
I've been reading a lot sources since this morning but I haven't get any clear understanding on…

Plain_Dude_Sleeping_Alone
- 1,849
- 2
- 23
- 49
53
votes
4 answers
Spring Boot: autowire beans from library project
I'm struggling to autowire beans from my custom library, imported with gradle.
after reading couple of similar topics I am still unable to find solution.
I have a Spring Boot project that depends on another project (my custom library with…

maret
- 1,826
- 1
- 13
- 18
44
votes
6 answers
Error Injecting FeignClient from another Project
I am having trouble auto wiring a feign client from another project. It appears that the implementation of the feign client is not being generated and injected.
This is the error I am getting.
org.springframework.beans.factory.BeanCreationException:…

Wes
- 847
- 2
- 10
- 22
35
votes
4 answers
Using @ComponentScan or with only one class
I'm maintaining a project with two set of main packages, the project is using Spring and Spring MVC, one of these packages contains several controllers and is scanned using XML configuration ( ).
The problem is that there is…

Shadi
- 557
- 1
- 6
- 15
23
votes
2 answers
Spring boot component scan include a single class
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…

Anand Sunderraman
- 7,900
- 31
- 90
- 150
17
votes
1 answer
Component Scan not scanning sub packages
I have encountered a strange problem. I am under the impression that component scan scans the sub packages recursively if a top level package is specified for scanning.
My repositories and entities are the maven dependency of the project. They live…

Nikhil Sahu
- 2,463
- 2
- 32
- 48
15
votes
1 answer
Is there a naming convention for @ComponentScan basePackageClasses?
Spring's @ComponentScan offers a type-safe basePackageClasses attribute - seems a good thing to use especially as it isn't uncommon for packages to be renamed on the project I'm working on. The documentation says:
Consider creating a special no-op…

Steve Chambers
- 37,270
- 24
- 156
- 208
12
votes
1 answer
How does ComponentScan work?
@ComponentScan will give you a list of all the classes with the @Component annotation in a package (or @Service/@Repository). To do this I imagine they use reflection to enumerate all the classes in a package and find the ones with that…

David says Reinstate Monica
- 19,209
- 22
- 79
- 122
10
votes
3 answers
How to get list of Interfaces from @ComponentScan packages
I would like to implement something similar to Spring Data.
Developer can define some interfaces, add a custom annotation to the interfaces to mark them, (my code will create Proxy instances for the interfaces) and use them by @Autowire to…

StanislavL
- 56,971
- 9
- 68
- 98
8
votes
3 answers
@ComponentScan with multiple configuration class : Annotation Based Configuration
As per Spring Doc-
Configures component scanning directives for use with @Configuration classes. Provides support parallel with Spring XML's element.
In my spring web application there are multiple files those are marked…
user4768611
7
votes
2 answers
Spring boot auto configuration with dependency and without @ComponentScan
Spring boot provides @ComponentScan to find packages to be scanned.
I am building a library which has @RestControllers inside with package com.mylib.controller. There are other classes as well with stereotype annotations in different packages.
So,…

Nitul
- 997
- 12
- 35
7
votes
2 answers
SpringBootApplication exclude when ComponentScanning other @SpringBootApplications
I'm having some difficulty preventing Spring Boot from auto configuring some classes (in this example: SolrAutoConfiguration). To illustrate I've setup a much reduced example:
https://github.com/timtebeek/componentscan-exclusions
In reality there's…

Tim
- 19,793
- 8
- 70
- 95
6
votes
3 answers
Spring @ComponentScan doesn't work on @Repository
I have a repository in different package than the configuration class , so I annotated it as the following with @Repostiory:
package test;
@Repository
public interface UserTest extends JpaRepository {
}
I have done the component scan…

Mohammad Karmi
- 1,403
- 3
- 26
- 42
6
votes
2 answers
Why is Spring @Configuration class inheritance not working as expected?
I have an abstract Spring configuration class that includes a common bean:
public abstract class AbstractConfig {
@Bean
public CommonBean commonBean {
CommonBean commonBean = new CommonBean();
commonBean.specifics =…

Steve Chambers
- 37,270
- 24
- 156
- 208