I'm using Spring Data Jpa, this is my project structure:
App
ConfigPackage
MyConfig
ServicePackage
MyService
RepositoryPackage
MyRepository
Here is the MyRepository
:
public interface MyRepository extends JpaRepository<MyEntity, Long> {
}
Here is the MyService
:
@Service
public class MyService {
@Autowired
private MyRepository myRepository; <---here
...
}
Here is the MyConfig
:
@Configuration
@EnableJpaRepositories(
basePackages = "RepositoryPackage",
entityManagerFactoryRef = "xxx",
transactionManagerRef = "xxx"
)
public class MyConfig {
}
I use @Autowired
to inject MyRepository
to MyService
, but IntelliJ always complains
Could not autowire. No beans of 'MyRepository' type found
even if the code can compile and run successfully.
Why can not IntelliJ recognize this is not an error? How to remove the warning of IntelliJ?
IntelliJ Version: 2018.2.6
Note this is for IntelliJ IDEA 2018.3.3 Ultimate Edition (But should work for other versions too)
I've noticed that this errors occurs (at least in my projects) when a configuration uses @ComponentScan
and thus loads another class annotated with @Configuration
. IntelliJ seems to not fully recognize it which leads to the error/warning:
xRepository
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