弹簧工具例外

时间:2018-04-06 08:26:52

标签: spring

我想用spring工具运行一个简单的程序,但是我得到了很多异常。

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添加到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>

所以我得到下面的例外。

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)
-------

注意:DataBase(springtoolfirstapp)内容表(客户)内容3个字段(id-name-phone) 我用MySQL工作台创建..

请帮帮我。我尝试了不同的方法,但没有成功..

0 个答案:

没有答案