How using spring-boot-starter-jpa in custom spring-boot-starter?

359 views Asked by At

I have my custom starter. Inside it, I define a repository. How should I define it in the configuration? This is how I did the usual bean before.

@Bean
@ConditionalOnMissingBean(HelloWorldController.class)
public HelloWorldController helloWorldController() {
    return new HelloWorldController();
}

Repository:

@Repository
public interface CarRepository extends JpaRepository<Car, Long> {
}

And configuration

@Configuration
@EnableJpaRepositories
public class DomainConfiguration {
}

If you use this starter, context will not see the repository bean. Because I did not declare it in the configuration.I don't know how to declare it.

1

There are 1 answers

0
IlnarMT On

In the configuration class, you must use the @EnableJpaRepositories and @EntityScan annotations, indicating the package in which the Repositories and Entity classes are located

@Configuration
@EnableJpaRepositories(basePackages = {"com.my.app.repository"})
@EntityScan(basePackages = {"com.my.app.entity"})
public class DomainConfiguration  {
}