Simple util to help loading presentation/development data for your Spring based application.
<dependency>
<groupId>com.github.matek2305</groupId>
<artifactId>spring-data-loader</artifactId>
<version>0.9.0</version>
</dependency>
After adding dependency to your pom.xml, build.gradle etc. you must mark your configuration (or main class when using Spring Boot) with @EnableDataLoader
annotation like in example below (@Profile("dev")
is not needed):
@Profile("dev")
@Configuration
@EnableDataLoader
public class DevDataLoaderConfiguration {
}
After that all your beans implementing DataLoader
interface will be executed during application startup so you can place your data there. If there are more than one bean and one depends on another there is @LoadDataAfter
annotation to mark dependencies.
@Component
@LoadDataAfter(RoleDataLoader.class)
public class UserDataLoader implements DataLoader {
@Override
public void load() {
// this will be exected after RoleDataLoader#load
}
}
@Component
public class RoleDataLoader implements DataLoader {
@Override
public void load() {
// load your roles data here
}
}
You can check usage example of spring-data-loader here.
This is my first public utility library and I would be grateful for your improvement ideas, so feel free to open an issue or contribute.