springを用いて表示させようとしたらエラーになる
解決したいこと
データベースに書いた内容をspringを使用し、表示させようと考えています。しかしエラーがどうやっても消えません。自分であれこれ試しましたが解決しないのでお力添えをいただければと思います。
発生している問題・エラー
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 18.154 s <<< FAILURE! - in jp.co.sss.shop.SharedShop3ApplicationTests
[ERROR] contextLoads Time elapsed: 0.007 s <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
[INFO]
[INFO] Results:
[INFO]
[ERROR] Errors:
[ERROR] SharedShop3ApplicationTests.contextLoads » IllegalState Failed to load Applica...
[INFO]
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 28.589 s
[INFO] Finished at: 2022-08-23T16:05:08+09:00
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "pom.xml" could not be activated because it does not exist.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project shared_shop3: There are test failures.
[ERROR]
[ERROR] Please refer to C:\Users\宮城\Desktop\shared_shop_SelectJoin\shared_shop3\target\surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
該当するソースコード
エンティティ部分
package jp.co.sss.shop.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
@Entity
@Table(name = "items")
public class Item {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_items_gen")
@SequenceGenerator(name = "seq_items_gen", sequenceName = "seq_items",
allocationSize = 1)
private Integer id;
@Column
private String name;
@Column
private Integer price;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getPrice() {
return price;
}
public void setPrice(Integer price) {
this.price = price;
}
}
リポジトリ部分
package jp.co.sss.shop.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import jp.co.sss.shop.entity.Item;
public interface ItemRepository extends JpaRepository<Item, Integer>{
}
コントローラー部分
package jp.co.sss.shop.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import jp.co.sss.shop.repository.ItemRepository;
@Controller
public class ItemController {
@Autowired
ItemRepository repository;
@RequestMapping("/items/findAll")
public String showItemList(Model model) {
model.addAttribute("items", repository.findAll());
return "items/item_list";
}
}
ビュー部分
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8" />
<title>Insert title here</title>
</head>
<body>
<div>商品一覧</div>
<table>
<tr>
<th>商品番号</th>
<th>商品名</th>
<th>価格</th>
</tr>
<tr th:each="item: ${items}">
<td th:text="${item.id}"></td>
<td th:text="${item.name}"></td>
<td th:text="${item.price}"></td>
</tr>
</table>
</body>
</html>
自分で試したこと
エラーメッセージ等を用いて検索したりしているのですが、はっきりしたことがわかっていません。
どなたかお教えいただけたら幸いです。
0 likes