I had this same issue when creating a Spring Boot application using their @SpringBootApplication
annotation. This annotation represents @Configuration
, @EnableAutoConfiguration
and @ComponentScan
according to the spring reference.
As expected, the new annotation worked properly and my application ran smoothly but, Intellij kept complaining about unfulfilled @Autowire
dependencies. As soon as I changed back to using @Configuration
, @EnableAutoConfiguration
and @ComponentScan
separately, the errors ceased. It seems Intellij 14.0.3 (and most likely, earlier versions too) is not yet configured to recognise the @SpringBootApplication
annotation.
For now, if the errors disturb you that much, then revert back to those three separate annotations. Otherwise, ignore Intellij...your dependency resolution is correctly configured, since your test passes.
Always remember...
Man is always greater than machine.
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 version of IntelliJ IDEA Ultimate (2016.3.4 Build 163) seems to support this. The trick is that you need to have enabled the Spring Data plugin.
Sometimes you are required to indicate where @ComponentScan should scan for components. You can do so by passing the packages as parameter of this annotation, e.g:
@ComponentScan(basePackages={"path.to.my.components","path.to.my.othercomponents"})
However, as already mentioned, @SpringBootApplication annotation replaces @ComponentScan, hence in such cases you must do the same:
@SpringBootApplication(scanBasePackages={"path.to.my.components","path.to.my.othercomponents"})
At least in my case, Intellij stopped complaining.
I always solve this problem doing de following.. Settings>Inspections>Spring Core>Code than you shift from error to warning the severity option
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{
/**/
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With