Closed sebasira closed 4 years ago
@sebasira sorry for the delay! Did you find a solution to your issue?
I think the error At least one JPA metamodel must be present!
is due to the fact that Spring does not find any @Entity
class (obviously!).
@EnableJpaRepositories
looks for classes in its package (like com.test
), unless its basePackageClasses attribute is overriden.
Closed due to inactivity, please reopen if needed.
For anyone in the same situation, I solve it by separating the configuration from the main class.
At first I had:
File App.java:
@SpringBootApplication(scanBasePackages = "ar.com.sebasira.*")
@EnableJpaRepositories(repositoryFactoryBeanClass = DataTablesRepositoryFactoryBean.class)
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
And then I create another file which I named AppConfig.java
and move there the @EnableJpaRepositories annotation. So it became:
File App.java:
@SpringBootApplication(scanBasePackages = "ar.com.sebasira.*")
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
File AppConfig.java
@Configuration
@EntityScan("ar.com.sebasira.*")
@ComponentScan(basePackages = { "ar.com.sebasira.*" })
@EnableJpaRepositories(basePackages = {"ar.com.sebasira.*"}, repositoryFactoryBeanClass = DataTablesRepositoryFactoryBean.class)
public class AppConfig {
}
Hello!
I'm learning how to test my code. In my first test, I was testing a simple dumb controller just to check it and I get this error
I could solve it by disabling the @EnableJpaRepositories annotations (found over stack overflow)
The testing I'm doing is not of the full app, just a slice using @WebMvcTest. When testing with @SpringBootTest this problem is gone.
Do you know how can I successfully run my test with out disabling that annotation? Thank you!