Seeder

Seeders populate your database with initial or test data. Annotate your class with @Seeder and implement SeederInterface — the framework runs them automatically at startup. Use the priority parameter to control execution order when multiple seeders depend on each other.

Create a seeder
@Seeder(priority = 10)
public class ArticleSeeder implements SeederInterface {

    @Inject
    private ArticleRepository articleRepository;

    @Override
    public void seed() {
        if (!articleRepository.findAll().isEmpty()) {
            return;
        }

        articleRepository.create(
            "Getting started with Obsidian",
            "Obsidian is a lightweight Java web framework..."
        );

        articleRepository.create(
            "Building REST APIs",
            "Learn how to build REST APIs with Obsidian..."
        );
    }
}
💡 Execution order
  • • Seeders run automatically at startup, before the server accepts requests
  • • Lower priority values run first — use this when seeders depend on each other
  • • Always guard with an existence check to avoid duplicate data on restart
  • @Inject works in seeders the same way as in controllers