前提・実現したいこと
PostgreSQL12.8から統計データを取得して表示させたいです。
データベース、ユーザーを作り、A5:SQL Mk-2によりデータをインポートし、
ソースを書いてSTSを実行したところ、以下のエラーメッセージが発生しました。
発生している問題・エラーメッセージ
ネットでログメッセージを調べ、pom.xmlにdependencyを追加、application.propertiesを修正等しましたが、どうやってもPostgreSQLにアクセスしている気配がないため、ご教授お願い致します。
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2021-12-17 09:56:42.521 ERROR 39472 --- [ main] o.s.boot.SpringApplication : Application run failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Factory method 'entityManagerFactory' threw exception; nested exception is java.lang.RuntimeException: Driver net.sourceforge.jtds.jdbc.Driver claims to not accept jdbcUrl, jdbc:postgresql://localhost:5432/otnj?user=otnj&sslmode=disable&password=<masked> at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.13.jar:5.3.13] 中略 Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Factory method 'entityManagerFactory' threw exception; nested exception is java.lang.RuntimeException: Driver net.sourceforge.jtds.jdbc.Driver claims to not accept jdbcUrl, jdbc:postgresql://localhost:5432/otnj?user=otnj&sslmode=disable&password=<masked> at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.13.jar:5.3.13] at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.13.jar:5.3.13] ... 19 common frames omitted Caused by: java.lang.RuntimeException: Driver net.sourceforge.jtds.jdbc.Driver claims to not accept jdbcUrl, jdbc:postgresql://localhost:5432/otnj?user=otnj&sslmode=disable&password=<masked> at com.zaxxer.hikari.util.DriverDataSource.<init>(DriverDataSource.java:110) ~[HikariCP-4.0.3.jar:na] 中略 ... 20 common frames omitted
該当のソースコード
pom.xml
xml
1<?xml version="1.0" encoding="UTF-8"?> 2<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4 <modelVersion>4.0.0</modelVersion> 5 <parent> 6 <groupId>org.springframework.boot</groupId> 7 <artifactId>spring-boot-starter-parent</artifactId> 8 <version>2.6.1</version> 9 <relativePath/> <!-- lookup parent from repository --> 10 </parent> 11 <groupId>com.sct</groupId> 12 <artifactId>OTNJSpring</artifactId> 13 <version>0.0.1</version> 14 <name>OTNJSpring</name> 15 <description>OTNJ Spring Project for Spring Boot</description> 16 <properties> 17 <java.version>11</java.version> 18 </properties> 19 <dependencies> 20 <dependency> 21 <groupId>org.springframework.boot</groupId> 22 <artifactId>spring-boot-starter-thymeleaf</artifactId> 23 </dependency> 24 <dependency> 25 <groupId>org.springframework.boot</groupId> 26 <artifactId>spring-boot-starter-web</artifactId> 27 </dependency> 28 29 <dependency> 30 <groupId>org.postgresql</groupId> 31 <artifactId>postgresql</artifactId> 32 <scope>runtime</scope> 33 </dependency> 34 <dependency> 35 <groupId>org.springframework.boot</groupId> 36 <artifactId>spring-boot-starter-data-jpa</artifactId> 37 </dependency> 38 39 <dependency> 40 <groupId>javax.xml.bind</groupId> 41 <artifactId>jaxb-api</artifactId> 42 </dependency> 43 44 <dependency> 45 <groupId>net.sourceforge.jtds</groupId> 46 <artifactId>jtds</artifactId> 47 </dependency> 48 49 <dependency> 50 <groupId>org.springframework.boot</groupId> 51 <artifactId>spring-boot-starter-jdbc</artifactId> 52 </dependency> 53 54 <dependency> 55 <groupId>org.hibernate</groupId> 56 <artifactId>hibernate-core</artifactId> 57 </dependency> 58 59 <dependency> 60 <groupId>org.hibernate</groupId> 61 <artifactId>hibernate-entitymanager</artifactId> 62 </dependency> 63 64 <dependency> 65 <groupId>org.springframework.boot</groupId> 66 <artifactId>spring-boot-starter-test</artifactId> 67 <scope>test</scope> 68 </dependency> 69 </dependencies> 70 71 <build> 72 <plugins> 73 <plugin> 74 <groupId>org.springframework.boot</groupId> 75 <artifactId>spring-boot-maven-plugin</artifactId> 76 </plugin> 77 </plugins> 78 </build> 79 80</project>
application.properties
properties
1spring.datasource.url=jdbc:postgresql://localhost:5432/otnj?user=otnj&sslmode=disable&password=otnj 2spring.datasource.username=otnj 3spring.datasource.password=otnj 4spring.datasource.driver-class-name=net.sourceforge.jtds.jdbc.Driver 5logging.level.org.hibernate.SQL=DEBUG 6logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE 7logging.level.org.springframework.web=DEBUG 8logging.level.org.hibernate=DEBUG 9spring.jpa.show-sql=true 10spring.jpa.properties.hibernate.format_sql=true
SQL
1create table stat( 2 id integer 3 , row integer 4 , col integer 5 , data double precision not null 6 , constraint stat_pk1 primary key (id, row, col) 7)
Java
1import org.springframework.boot.SpringApplication; 2import org.springframework.boot.autoconfigure.SpringBootApplication; 3 4@SpringBootApplication 5public class OtnjSpringApplication { 6 7 public static void main(String[] args) { 8 SpringApplication.run(OtnjSpringApplication.class, args); 9 } 10 11}
Java
1import java.util.List; 2 3import org.springframework.beans.factory.annotation.Autowired; 4import org.springframework.stereotype.Controller; 5import org.springframework.ui.Model; 6import org.springframework.web.bind.annotation.GetMapping; 7 8@Controller 9public class StatController { 10 @Autowired 11 private StatService statService; 12 13 @GetMapping(value = "/stat") 14 public String displayList(Model model) { 15 List<Stat> statList = statService.searchAll(); 16 model.addAttribute("statList", statList); 17 return "stat"; 18 } 19}
Java
1import java.util.List; 2 3import org.springframework.beans.factory.annotation.Autowired; 4import org.springframework.stereotype.Service; 5 6@Service 7public class StatService { 8 9 @Autowired 10 private StatRepository statRepository; 11 12 public List<Stat> searchAll() { 13 return statRepository.findAll(); 14 } 15}
Java
1import org.springframework.data.jpa.repository.JpaRepository; 2import org.springframework.stereotype.Repository; 3 4@Repository 5public interface StatRepository extends JpaRepository<Stat, StatCell> { 6 7}
Java
1import javax.persistence.Column; 2import javax.persistence.Embeddable; 3 4@Embeddable 5public class StatCell { 6 @Column(name = "id") 7 private Integer id; 8 9 @Column(name = "row") 10 private Integer row; 11 12 @Column(name = "col") 13 private Integer col; 14}
Java
1import java.io.Serializable; 2 3import javax.persistence.Column; 4import javax.persistence.EmbeddedId; 5import javax.persistence.Entity; 6import javax.persistence.IdClass; 7import javax.persistence.Table; 8 9@Entity 10@Table(name="stat") 11@IdClass(value=StatCell.class) 12public class Stat implements Serializable { 13 14 private static final long serialVersionUID = 6501935237628672264L; 15 16 @EmbeddedId 17 private StatCell cell; 18 19 @Column(name = "data") 20 private Double data; 21}
html
1<!DOCTYPE html> 2<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"> 3 <head> 4 <title>推移</title> 5 <meta charset="utf-8" /> 6 </head> 7 <body> 8 <h1>推移</h1> 9 <table> 10 <thead> 11 <tr> 12 <th>年</th> 13 <th>数</th> 14 </tr> 15 </thead> 16 <tbody> 17 <tr th:each="stat : ${statList}" th:object="${stat}"> 18 <td class="center" th:text="*{row}"></td> 19 <td class="center" th:text="*{data}"></td> 20 </tr> 21 </tbody> 22 </table> 23 </body> 24</html>
試したこと
JDBCのURLとデータ取得をpsqlで確認しました。
bash
1> psql -d 'postgresql://localhost:5432/otnj?user=otnj&sslmode=disable&password=otnj' 2psql (12.8) 3Type "help" for help. 4 5otnj=> select * from stat; 6 id | row | col | data 7----+------+-----+---------- 8 1 | 1964 | 1 | 352832 9 1 | 1965 | 1 | 366649 10 1 | 1966 | 1 | 432937 11省略 12(58 rows) 13 14otnj=>
補足情報(FW/ツールのバージョンなど)
sts-4.13.0.RELEASE
回答1件
あなたの回答
tips
プレビュー