Questions tagged [component-scan]

Questions regarding using `@ComponentScan` to detect Spring managed components

129 questions
2
votes
1 answer

@ComponentScan in Spring (not Boot) doesn't scans subpackages

My project is situated in package home.bank_application. There are a lot of subpackages, such as 'controller', 'dao', 'service', 'config' etc... When I annotated my WebConfigClass as @ComponentScan(basePackages = "home.bank_application") my…
2
votes
1 answer

SpringBoot not recognizing multiple @ComponentScan meta-annotations

I noticed a problem with Spring's @ComponentScan annotation when used as a meta-annotation. In the following example project structure, both the FirstHandler and SecondService classes should be scanned as components and registered as…
Alexander D.
  • 91
  • 1
  • 5
2
votes
1 answer

How can I override the Spring component scanning when running a JUnit 5 test?

I have this JUnit 5 test: @SpringBootTest public class MyTest { ... } The application default configuration loads many @Component's @Service's and @Configuration's. For some tests, I would like to tell the Spring application running in this…
Gabriel Petrovay
  • 20,476
  • 22
  • 97
  • 168
2
votes
1 answer

How to see the list of classpath scanned by @ComponentScan to resolve NoSuchBeanDefinitionException

In a Spring boot 1.5.9 application, I have @SpringBootApplication on my main class. I also have @KopaxgroupApi annotation, with : @Retention(RUNTIME) @Target(TYPE) @Import(KopaxgroupApiConfig.class) public @interface KopaxgroupApi { …
Dimitri Kopriwa
  • 13,139
  • 27
  • 98
  • 204
2
votes
3 answers

Spring Boot: How to include a configuration class that is not in my base package?

I've got a fairly standard spring boot app which is built with gradle from several gradle modules. Here's the directory layout: - root - serviceA - src/main/java - org.example.serviceA - ServiceAApplication.java -…
Martin Häusler
  • 6,544
  • 8
  • 39
  • 66
2
votes
3 answers

Spring conditional component scan configuration

I have a configuration class which registers beans based on a very simple condition (checking a property value in application.properties). The configuration class and the condition are the following:…
2
votes
2 answers

@SpringBootApplication - ComponentScan does not work as intended in new Eclipse project

I recently started using Eclipse (moved from IntelliJ Idea) but whatever new SpringBoot app I start writing, I always get this problem. The @SpringBootApplication on my main class does not work as intended. I should be able to get away without…
Bence
  • 119
  • 1
  • 11
2
votes
1 answer

Spring Documentation for Component Scan versus Configuration

I've searched for an answer to this question but my search voodoo must be a little off. At work I've noticed there's a preference to use Spring Configuration and @Beans to initialise our Java objects. While there is no problem with this approach I…
Shane Gannon
  • 6,770
  • 7
  • 41
  • 64
2
votes
1 answer

How to config @ComponentScan dynamic?

@ComponentScan( //CS1 basePackages = {"com.package.A", "com.package.B"}, excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = {com.Package.A.SomeClass.class …
Dai Kaixian
  • 1,045
  • 2
  • 14
  • 24
2
votes
1 answer

How to exclude test folder from component scan annotation in spring

App |-src |-com |-xx |-model |-IclassA.java |-impl |-ClassA.java |-test |-com |-xx |-model |-Conf.java …
USer22999299
  • 5,284
  • 9
  • 46
  • 78
2
votes
0 answers

Spring component scan using property not working for multiple base packages

I want to read a variable which keeps the packages name to scan from a properties file: pluginpackages=com.x.a,com.x.b This does work neither with nor with @ComponentScan(basePackages =…
2
votes
1 answer

ComponentScan and Autowired not working for dependent Spring project?

I have two projects A and B. Both are built with Maven, and project A has a Maven dependency to project B. Both project have a class with @Configuration annotation where I define @Beans. I have beans in project A, from both projects. If I use the…
user1340582
  • 19,151
  • 35
  • 115
  • 171
2
votes
1 answer

Can I use @ComponentScan and @Autowired with BasicDataSource without declare bean for BasicDataSource class in XML?

I'm trying to integrate hibernate with spring, and I asked-just to know if that possible or not-, can I use @Autowired and @Componentscan to do inject the BasicDataSource class?
Ibrahim
  • 77
  • 3
  • 10
2
votes
1 answer

Grails: How to specify Spring component scan exclusions using the bean build DSL

I have some Spring components declared using annotations and I need to use them inside a Grails application. What I need to do is a component scan from a base package, while excluding some of the components inside the package, using BeanBuilder DSL…
Jaime A. García
  • 146
  • 1
  • 10
2
votes
2 answers

component-scan can not detect interface bean?

This is part of my root-context.xml in spring mvc project(3.2.8 RELEASE). And I got some structures like…
Juneyoung Oh
  • 7,318
  • 16
  • 73
  • 121
1 2
3
8 9