I have created a simple unit test but IntelliJ is incorrectly highlighting it red. marking it as an error
No beans?
I am using this annotation to hide this error when it appears in IntelliJ v.14:
@SuppressWarnings("SpringJavaAutowiringInspection")
Configure application context and all will be ok.
in my Case, the Directory I was trying to @Autowired was not at the same level,
after setting it up at the same structure level, the error disappeared
hope it can helps some one!
Add Spring annotation @Repository
over the repository class.
I know it should work without this annotation. But if you add this, IntelliJ will not show error.
@Repository
public interface YourRepository ...
...
If you use Spring Data with extending Repository
class it will be conflict pagkages. Then you must indicate explicity pagkages.
import org.springframework.data.repository.Repository;
...
@org.springframework.stereotype.Repository
public interface YourRepository extends Repository<YourClass, Long> {
...
}
And next you can autowired your repository without errors.
@Autowired
YourRepository yourRepository;
It probably is not a good solution (I guess you are trying to register repositorium twice). But work for me and don't show errors.
Maybe in the new version of IntelliJ can be fixed: https://youtrack.jetbrains.com/issue/IDEA-137023
My solution to this issue in my spring boot application was to open the spring application context and adding the class for the missing autowired bean manually!
(access via Project Structure menu or spring tool window... edit "Spring Application Context")
So instead of SpringApplicationContext just containing my ExampleApplication spring configuration it also contains the missing Bean:
SpringApplicationContext:
et voilà: The error message disappeared!
It can be solved by placing @EnableAutoConfiguration on spring boot application main class.