Reputation: 2703
Stuying Springboot, I got myself into an infinite wormhole of errors. Here is the last one: No qualifying bean of type 'ca.company.hello.A' available
However, what puzzles me is that I do define the bean:
@Configuration
public class Config {
@Bean
public B b() {
return new B();
}
@Bean
public A a() {
return new A();
}
}
And use it like this:
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
@Profile("client_app_profile_name")
@SpringBootApplication
public class Helloer {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(Helloer.class, args);
A a = ctx.getBean(A.class);
a.speak();
}
}
Here is my file structure:
Here is class A, just in case:
@Component
public class A {
@Autowired
private B b;
@Value("Covid 19")
private String calamity;
public void speak() {
b.writeToScreen(this.calamity);
}
}
Can someone please give me a hint as to what more Springboot wants from me? ;)
P.S.
If I remove the Bean A
from Config
, same error persists:
@Configuration
public class Config {
@Bean
public B b() {
return new B();
}
}
Upvotes: 0
Views: 252
Reputation: 1353
I could reproduce your problem.
1 - Move your Helloer class to inside ca.company package. Spring classpath scanning won't work if Helloer is at the same level as ca.company and you will get some error like below:
This can also happen if you are @ComponentScanning a springframework package (e.g. if you put a @ComponentScan in the default package by mistake)
Your structure should be:
- java
- ca.company
- config
- hello
Helloer
2 - With spring classpath scan working, you can remove your bean definitions from your Configuration classes, as you will get a double bean definition error.
3 - Remove the annotations you added to suppress the errors in [1].
Upvotes: 2