I have created a simple unit test but IntelliJ is incorrectly highlighting it red. marking it as an error
No beans?
I just had to use @EnableAutoConfiguration to address it, however this error had no functional impact.
I had a similar problem in my application. When I added annotations incorrect highliting dissapeared.
@ContextConfiguration(classes = {...})
Check if you missed @Service annotation in your service class, that was the case for me.
And one last piece of important information - add the ComponentScan
so that the app knows about the things it needs to wire. This is not relevant in the case of this question. However if no @autowiring
is being performed at all then this is likely your solution.
@Configuration
@ComponentScan(basePackages = {
"some_package",
})
public class someService {
Surprisingly, A Feign oriented project that successfully ran with Eclipse could not run in InteliJ. When started the application, InteliJ complained about the Feign client I tried to inject to the serviceImpl layer saying: field personRestClient (my Feign client) in ... required a bean of type ... that could not be found. Consider defining a bean of type '....' in your configuration.
I wasted a long time trying to understand what is wrong. I found a solution (for InteliJ) which I do not completely understand:
Or choose Eclipse :)
Check if the package of your bean is written correctly
//Check if this is written right
package com.package1.package2.package3
import ...
@Service
class ServiceX {
...
}