1

I want to run a simple program with spring tool, but I get so many Exceptions.

1-Application.java

spring.datasource.url=jdbc:mysql://localhost:3306/springbootfirstapp
spring.datasource.username=root
spring.datasource.password=
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.ddl-auto=update  

2-CustomerController.java

package springbootfirstapp.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import springbootfirstapp.domain.Customer;
import springbootfirstapp.repo.CustomerRepo;

@RestController
@RequestMapping("/customer")
public class CustomerController {


@Autowired
CustomerRepo rp;

@RequestMapping("/findall")
@ResponseBody
public List<Customer> findall(){
return rp.findAll();
    }



}

3-Customer.java

package springbootfirstapp.domain;

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

@Entity
public class Customer {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private String name;
private int phone;
public int getId() {
    return id;
}
public void setId(int id) {
    this.id = id;
}
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public int getPhone() {
    return phone;
}
public void setPhone(int phone) {
    this.phone = phone;
}
public Customer(int id, String name, int phone) {
    super();
    this.id = id;
    this.name = name;
    this.phone = phone;
}
public Customer() {
    super();
}





}

4-CustomerRepo.java

package springbootfirstapp.repo;

import org.springframework.data.jpa.repository.JpaRepository;

import springbootfirstapp.domain.Customer;

public interface CustomerRepo extends JpaRepository<Customer, Integer> {

}

5-application.properties

spring.datasource.url=jdbc:mysql://localhost:3306/springbootfirstapp
spring.datasource.username=root
spring.datasource.password=
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.ddl-auto=update

6-I add to pom.xml

 <dependency>
     <groupId>org.slf4j</groupId>
     <artifactId>slf4j-api</artifactId>
     <version>1.7.5</version>
 </dependency>
 <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>1.7.5</version>
 </dependency>

so I am getting the Exception below.

Exception in thread "main" java.lang.StackOverflowError
at org.apache.log4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:39)
at org.apache.log4j.LogManager.getLogger(LogManager.java:45)
-------

note: DataBase (springtoolfirstapp) content table (customer) content 3 fields (id-name-phone) and I create with MySQL workbench..

Please help me. I have tried different approaches and they did not succeed..

David Kariuki
  • 1,522
  • 1
  • 15
  • 30
  • Which exceptions? On Application.java you copied/pasted the application.properties – Andrea Girardi Apr 06 '18 at 08:51
  • Post the complete stacktrace as text, not as an image and not just part of it. Especially look at the bottom of the stacktrace, it contains information on why the application could not start up. – Jesper Apr 06 '18 at 09:41
  • sorry. I first used this tool and found it difficult .. I modified the exception information at the bottom .. – warda Jouria Apr 06 '18 at 12:05
  • Check this anser: https://stackoverflow.com/questions/32366586/using-log4j2-with-slf4j – Andrea Girardi Apr 06 '18 at 12:45
  • thank you, I looked at the question and the reply, but I do not know how delete the library because I have different libraries and I'm just opening the project The libraries appear again .. – warda Jouria Apr 06 '18 at 16:05

0 Answers0