Skip to content

Files

Latest commit

ce66646 · Feb 14, 2016

History

History
61 lines (46 loc) · 2.37 KB

README.md

File metadata and controls

61 lines (46 loc) · 2.37 KB

Build Status codecov.io Dependency Status Maven Central Codacy Badge

spring-data-loader

Simple util to help loading presentation/development data for your Spring based application.

Maven

<dependency>
    <groupId>com.github.matek2305</groupId>
    <artifactId>spring-data-loader</artifactId>
    <version>0.9.0</version>
</dependency>

Usage

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
    }
}

Example

You can check usage example of spring-data-loader here.

Contribute

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.