"Could not autowire. No beans of type... found" with Simple project
A couple of possibilities here.
You need to add the @EnableJpaRepositories(basePackages = {"your.pkg.here"})
to the TestApplication
. This tells Spring Data to look for your repository classes under the specified package. If the repository package name is the same as the TestApplication
, you can skip the basePackages
part.
Similarly, if your TestApplication
and SimpRepository
are not in the same package, you need to add a @ComponentScan
with the list of all relevant packages.
intellij incorrectly saying no beans of type found for autowired repository
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.
How do I fix "Could not autowire. No beans of 'MyRepository' type found"?
You could try this, set your package in @ComponentScan
of the class AppConfig
:
@ContextConfiguration(classes = AppConfig.class)
@ExtendWith(SpringExtension.class)
public class AdminEvaluatorTest {
@Autowired MyRepository myRepository;
@Configuration
@ComponentScan("com.<your-package>")
public static class AppConfig {
}
}
Related Topics
How to Check If a Date Is Within a Certain Range
How to Convert Linkedhashmap to Custom Java Object
How to Get the Average of a 2D Array
Showing Morning, Afternoon, Evening, Night Message Based on Time in Java
Java 8 Convert Utc Time to Edt/Est So That Date Remains the Same
How to Valid @Requestheader in Spring Boot
Crudrepository How to Find by Last Date Between
Java.Io.Filenotfoundexception: (Access Is Denied)
No String-Argument Constructor/Factory Method to Deserialize from String Value ('')
How to Exclude Property from Lombok Builder
How to Take Input as String With Spaces in Java Using Scanner
How to Sort Date in Descending Order Using Comparator
How to Update Only the Incoming Fields in a Model Using Spring Data Jpa
How to Avoid Nullpointerexception With an Empty Cell Using Poi
How to Sort Integer Digits in Ascending Order Without Strings or Arrays