Reputation: 31
We have a requirement to disable @entity based on configuration. is it possible?
We dont want to create a table so we should disable only few entity.
Upvotes: 3
Views: 1393
Reputation: 10716
I can think of a couple of ways to handle this requirement, but the simplest one (assuming you're using Spring Boot) would probably be to group the required and optional entities in separate packages, and then setup the main configuration to include entities from the required package:
@SpringBootApplication
@EntityScan({"requiredpackageone", "requiredpackagetwo", ...})
public class MainApplication {
...
}
and then, enable entity scanning for the optional package, in an optional configuration:
@Configuration
@ConditionalOnProperty(...) // or @Profile, whichever works for you
@EntityScan("optionalpackage")
public class AdditionalEntityConfig {
// the class itself can be empty
}
Upvotes: 4