Roberto Conte Rosito

Setup Spring Boot with JPA and MySQL

Welcome back to my dev notes!

Few things that I’ve to remember next time I need to setup a Spring Boot project with JPA and MySQL:

  • Add the following dependencies to your pom.xml:
  • Add the following properties to your
  • Create your model using @Entity and @Id annotations:
public class User {
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;
  private String name;
  private String email;
  private String password;
  // getters and setters
  • Create your repository extending JpaRepository adding @Repository annotation:
public interface UserRepository extends JpaRepository<User, Long> {}

Now you are ready to @Autowired your repository and use it in your services/controllers.

That’s all for today, see you next time!

comments powered by Disqus