"Creatingbean error" occurs on springboot and boot fails

Asked 2 years ago, Updated 2 years ago, 87 views

Assumptions/What you want to realize
There is an error creating bean in springboot, so I would like to troubleshoot and start it.

I am developing a CRUD system using SpringBoot at STS to study on my own.
When I tried to start the server, the following error occurred and it didn't work.
I couldn't solve the problem by myself, so I would appreciate it if you could give me some advice from my predecessor.
Thank you for your cooperation.

Problem/Error Message Occurring

Communications link failure

BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource

Affected Source Codes

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/person_db
spring.datasource.username=root
spring.datasource.password=
package com.example.person.service;

import java.util.List;

import org.springframework.beans.factory.announcement.Autowired;
import org.springframework.stereotype.Service;

import com.example.person.entity.PersonEntity;
import com.example.person.repository.PersonRepository;

@Service
public class PersonService {

    @Autowired
    private PersonRepository personRepository;

    publicList<PersonEntity>findAll(){
        return personRepository.findAll();
    }

    publicPersonEntity findOne(longid){
        return personRepository.findById(id).orElse(null);
    }

    public PersonEntity save (PersonEntity person) {
        return personRepository.save(person);
    }

    public void delete (long id) {
        personRepository.deleteById(long)id);
    }
}
package com.example.person.entity;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

@Entity
@Table(name="person")
public class PersonEntity {
    @Id
    @GeneratedValue (strategy=GenerationType.IDENTITY)
    private long id;
    @NotEmpty
    private String name;
    @NotNull
    @Min(value=0)
    @Max(value=150)
    private age;
    @Size(max=20)
    private String Belong;
    private String workplace;

    public long getId() {
        return id;
    }
    public void setId(longid){
        this.id=id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name){
        this.name = name;
    }
    public int getAge(){
        return;
    }
    public void setAge(interage){
        This.age=age;
    }
    public String getBelong() {
        return bellong;
    }
    public void setTeam(String bellong) {
        This.belong=belong;
    }
    public String getWorkplace() {
        return workplace;
    }
<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
          <groupId>nz.net.ultraq.thymeleaf</groupId>
          <artifactId>thymeleaf-layout-dialect</artifactId>
        </dependency>
    </dependencies>

Only the possible source codes are listed.
Please let me know if you need anything else.

Tried
I looked it up on the internet and changed it to the following contents, and it was said that I could troubleshoot, so I tried it, but I couldn't solve it.
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
Review the annotation.

Additional Information (e.g. FW/Tool Version)
STS 4.2.0
SpringBoot
phpmyadmin

java mysql spring-boot

2022-09-30 17:32

1 Answers

The possible causes are listed in the reference link, but for the time being, it's easy to see:

spring.datasource.url=jdbc:mysql://localhost:3306/person_db

In , change localhost to 127.0.0.1 and try again.

Note:


2022-09-30 17:32

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.