I have created a simple unit test but IntelliJ is incorrectly highlighting it red. marking it as an error
No beans?
IntelliJ IDEA Ultimate
Add your main class to IntelliJ Spring Application Context, for example Application.java
File
-> Project Structure..
left side: Project Setting -> Modules
right side: find in your package structure
Spring
and add +
Application.java
I had similar issue in Spring Boot application. The application utilizes Feign (HTTP client synthetizing requests from annotated interfaces). Having interface SomeClient
annotated with @FeignClient
, Feign generates runtime proxy class implementing this interface. When some Spring component tries to autowire bean of type SomeClient
, Idea complains no bean of type SomeClient
found since no real class actually exists in project and Idea is not taught to understand @FeignClient
annotation in any way.
Solution: annotate interface SomeClient
with @Component
. (In our case, we don't use @FeignClient
annotation on SomeClient
directly, we rather use metaannotation @OurProjectFeignClient
which is annotated @FeignClient
and adding @Component
annotation to it works as well.)
As long as your tests are passing you are good, hit alt + enter
by taking the cursor over the error and inside the submenu of the first item you will find Disable Inspection
select that
Putting @Component
or @configuration
in your bean config file seems to work, ie something like:
@Configuration
public class MyApplicationContext {
@Bean
public DirectoryScanner scanner() {
return new WatchServiceDirectoryScanner("/tmp/myDir");
}
}
@Component
public class MyApplicationContext {
@Bean
public DirectoryScanner scanner() {
return new WatchServiceDirectoryScanner("/tmp/myDir");
}
}
Have you checked that you have used @services
annotation on top of your service implementation?
It worked for me.
import org.springframework.stereotype.Service;
@Service
public class UserServiceImpl implements UserServices {}
I am using spring-boot 2.0, and intellij 2018.1.1 ultimate edition and I faced the same issue.
I solved by placing @EnableAutoConfiguration in the main application class
@SpringBootApplication
@EnableAutoConfiguration
class App{
/**/
}