SpingREST:无法打开JPA EntityManager进行事务处理; 嵌套exception是org.hiberna

当我启动Postman看到我的SpringREST服务运行时,我收到以下错误:

 { "timestamp": 1506965117328, "status": 500, "error": "Internal Server Error", "exception": "org.springframework.transaction.CannotCreateTransactionException", "message": "Could not open JPA EntityManager for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection", "path": "/api/matchs" } 

我不知道错误在哪里,这里是项目的类:

的pom.xml

   4.0.0 com.kaluzny spring-boot-rest-api-postgresql 0.0.1-SNAPSHOT jar  org.springframework.boot spring-boot-starter-parent 1.5.3.RELEASE    UTF-8 UTF-8 1.8     org.springframework.boot spring-boot-starter-web   org.springframework.boot spring-boot-starter-data-rest   org.springframework.boot spring-boot-starter-data-jpa   org.springframework.boot spring-boot-starter-test test   org.springframework.boot spring-boot-starter-security    org.postgresql postgresql 9.4-1201-jdbc41 runtime    javax.inject javax.inject 1      org.springframework.boot spring-boot-maven-plugin    repackage        

Aplication.java

 package com.kaluzny; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } 

MatchRestController.java

 package com.kaluzny.web; import com.kaluzny.domain.*; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import javax.inject.Inject; import java.util.Collection; @RestController @RequestMapping("/api/matchs") public class MatchRestController { private MatchRepository repository; @Inject public void setRepository(MatchRepository repository) { this.repository = repository; } @RequestMapping( method = RequestMethod.POST) public ResponseEntity addMatch(@RequestBody Match match) { return new ResponseEntity(repository.save(match), HttpStatus.CREATED); } @RequestMapping( method = RequestMethod.GET) public ResponseEntity<Collection> getAllMatch() { return new ResponseEntity(repository.findAll(), HttpStatus.OK); } @RequestMapping( value = "/{idMatch}", method = RequestMethod.GET) public ResponseEntity getMatchWithIdMatch(@PathVariable Integer idMatch) { return new ResponseEntity(repository.findOne(idMatch), HttpStatus.OK); } @RequestMapping( value = "/{idMatch}", method = RequestMethod.PUT) public ResponseEntity updateMatchFromDB(@PathVariable("idMatch") Integer idMatch, @RequestBody Match match) { Match currentMatch = repository.findOne(idMatch); currentMatch.setIdMatch(match.getIdMatch()); currentMatch.setNumberPlayers(match.getNumberPlayers()); currentMatch.setWinner(match.getWinner()); currentMatch.setScore(match.getScore()); currentMatch.setNumberSpike(match.getNumberSpike()); currentMatch.setNumberFireball(match.getNumberFireball()); currentMatch.setNumberNuke(match.getNumberNuke()); Match currentMatch1 = repository.findOne(idMatch); return new ResponseEntity(repository.save(currentMatch1), HttpStatus.OK); } @RequestMapping( value = "/{idMatch}", method = RequestMethod.DELETE) public void deleteMatchWithId(@PathVariable Integer idMatch) { repository.delete(idMatch); } @RequestMapping( method = RequestMethod.DELETE) public void deleteAllMatchs() { repository.deleteAll(); } } 

MatchRepository.java

 package com.kaluzny.domain; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; import java.util.List; @RepositoryRestResource public interface MatchRepository extends JpaRepository { List findByIdMatch(Integer idMatch); } 

Match.java

 package com.kaluzny.domain; import javax.persistence.*; @Entity public class Match { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE) private Integer idMatch; private Integer numberPlayers; private String winner; private Integer score; private Integer numberSpike; private Integer numberFireball; private Integer numberNuke; public Match(Integer idMatch, Integer numberPlayers, String winner, Integer score, Integer numberSpike, Integer numberFireball, Integer numberNuke) { this.idMatch = idMatch; this.numberPlayers = numberPlayers; this.winner = winner; this.score = score; this.numberSpike = numberSpike; this.numberFireball = numberFireball; this.numberNuke = numberNuke; } public Match() { } public void setIdMatch(Integer idMatch){ this.idMatch = idMatch; } public Integer getIdMatch() { return idMatch; } public void setNumberPlayers(Integer numberPlayers){ this.numberPlayers = numberPlayers; } public Integer getNumberPlayers(){ return numberPlayers; } public void setWinner(String winner){ this.winner = winner; } public String getWinner(){ return winner; } public void setScore(Integer score){ this.score = score; } public Integer getScore(){ return score; } public void setNumberSpike(Integer numberSpike){ this.numberSpike = numberSpike; } public Integer getNumberSpike(){ return numberSpike; } public void setNumberFireball(Integer numberFireball){ this.numberFireball = numberFireball; } public Integer getNumberFireball(){ return numberFireball; } public void setNumberNuke(Integer numberNuke){ this.numberNuke = numberNuke; } public Integer getNumberNuke(){ return numberNuke; } @Override public String toString() { return "Partida{" + "Indentificador Partida: " + numberPlayers + '\'' + "Numero Jogadores: " + numberPlayers + '\'' + "Vencedor: "+ winner + '\'' + "Pontuação: " + score + '\'' + "Numero de Espinhos: " + numberSpike + '\'' + "Numero de Fireball" + numberFireball + '\'' + "Numero de Nukes" + numberNuke + '}'; } } 

正如我所说,我不知道问题出在哪里,我已经解决了其中的一些问题,但这个问题很困难。

感谢大家。

很明显,存在连接问题。 请检查您的application.properties文件,看看数据库配置是否正确。