O'Reilly logo

Learning Spring Boot by Greg L. Turnquist

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Loading data programmatically

What if we don't care for SQL? Or, what if we prefer to write code and let the compiler point out flaws in our setup? The alternative is to create a database-loading class using Spring Data APIs to do the heavy lifting:

package learningspringboot; import javax.annotation.PostConstruct; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service public class DatabaseLoader { private final TeammateRepository teammateRepository; private final TeamRepository teamRepository; @Autowired public DatabaseLoader(TeammateRepository teammateRepository, TeamRepository teamRepository) { this.teammateRepository = teammateRepository; this.teamRepository = teamRepository; } ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required