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