Mohamed Chiheb ben Jemaa Mohamed Chiheb ben Jemaa - 4 months ago 12
MySQL Question

spring boot data jpa mysql could not create database

I am new in spring
I will post my code,
that the


and this my entity

package model;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

public class Person {
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
private String name;
private String phone;
private String adresse;
public long getId() {
return id;
public void setId(long id) { = id;
public String getName() {
return name;
public void setName(String name) { = name;
public String getPhone() {
return phone;
public void setPhone(String phone) { = phone;
public String getAdresse() {
return adresse;
public void setAdresse(String adresse) {
this.adresse = adresse;
public Person(long id, String name, String phone, String adresse) {
super(); = id; = name; = phone;
this.adresse = adresse;
public Person() {


and this is the repository

package repositry;


import model.Person;

public interface PersonRespositry extends JpaRepository<Person, Long> {


and my controller

package contoller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import model.Person;

import repositry.PersonRespositry;

public class PersonController {

PersonRespositry rp;
public PersonController(PersonRespositry rp) {
// TODO Auto-generated constructor stub

public Person find(long id){
return rp.findOne(id);

public List<Person> findall(){
return rp.findAll();
public String Demo(){
return "Hello world !!";
@RequestMapping(value="/create", method=RequestMethod.GET)
public String create(){
Person p=new Person();
p.setAdresse("rue ");;
return " success";


This is the architect of the project:

When I run the application the database does not generate and only the
localhost:8080 is running.


Your problem is the location of the

@ComponentScanlooks for Spring beans inside the package of the class annotated with (@SpringBootApplication contains @ComponentScan) and in subpackages of this package.

I already provided an example to a very similar setup.

Please have a look here:

Furthermore the hint of Robert Moskal is correct. The database itself has to exist already. Only the tables will be created automatically.