Spring Boot入門という参考書を勉強しているのですが、参考書のとおりにコードを書いて実行するとエラーが出ます。
先週から解決策を調べているのですが、まだわかりません。
ご教授お願いいたします。
java
1package com.yamada.springboot; 2 3import org.springframework.beans.factory.annotation.*; 4import org.springframework.stereotype.Controller; 5import org.springframework.web.bind.annotation.RequestMapping; 6import org.springframework.web.servlet.ModelAndView; 7import com.yamada.springboot.repositories.MyDataRepository; 8 9@Controller 10public class HelloController { 11 12 @Autowired 13 MyDataRepository repository; 14 15 @RequestMapping("/") 16 public ModelAndView index(ModelAndView mav) { 17 mav.setViewName("index"); 18 mav.addObject("msg", "this is sample content."); 19 Iterable<MyData> list = repository.findAll(); 20 mav.addObject("data", list); 21 return mav; 22 } 23} 24
java
1package com.yamada.springboot; 2 3import javax.persistence.Column; 4import javax.persistence.Entity; 5import javax.persistence.GeneratedValue; 6import javax.persistence.GenerationType; 7import javax.persistence.Id; 8import javax.persistence.Table; 9 10@Entity 11@Table(name="mydata") 12 13public class MyData { 14 15 @Id 16 @GeneratedValue(strategy = GenerationType.AUTO) 17 @Column 18 private long id; 19 20 @Column(length = 50, nullable = false) 21 private String name; 22 23 @Column(length = 200, nullable = true) 24 private String mail; 25 26 @Column(nullable = true) 27 private Integer age; 28 29 @Column(nullable = true) 30 private String memo; 31 32 public long getId(){ 33 return id; 34 } 35 36 public void setId(long id){ 37 this.id = id; 38 } 39 40 public String getName(){ 41 return name; 42 } 43 44 public void setName(String name){ 45 this.name = name; 46 } 47 48 public String getMail(){ 49 return mail; 50 } 51 52 public void setMail(String mail){ 53 this.mail = mail; 54 } 55 56 public Integer getAge(){ 57 return age; 58 } 59 60 public void setAge(Integer age){ 61 this.age = age; 62 } 63 64 public String getMemo(){ 65 return memo; 66 } 67 68 public void setMemo(String memo){ 69 this.memo = memo; 70 } 71} 72
java
1package com.yamada.springboot.repositories; 2 3import com.yamada.springboot.MyData; 4import org.springframework.data.jpa.repository.JpaRepository; 5import org.springframework.stereotype.Repository; 6 7@Repository 8public interface MyDataRepository extends JpaRepository<MyData, Long>{ 9 10}
java
1package com.yamada.springboot; 2 3import org.springframework.boot.SpringApplication; 4import org.springframework.boot.autoconfigure.SpringBootApplication; 5 6@SpringBootApplication 7public class MyBootAppApplication { 8 9 public static void main(String[] args) { 10 SpringApplication.run(MyBootAppApplication.class, args); 11 } 12} 13
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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4 <modelVersion>4.0.0</modelVersion> 5 6 <groupId>com.yamada.springboot</groupId> 7 <artifactId>MyBootApp</artifactId> 8 <version>0.0.1-SNAPSHOT</version> 9 <packaging>jar</packaging> 10 11 <name>MyBootApp</name> 12 <description>sample project for Spring Boot</description> 13 14 <parent> 15 <groupId>org.springframework.boot</groupId> 16 <artifactId>spring-boot-starter-parent</artifactId> 17 <version>1.3.5.RELEASE</version> 18 <relativePath/> <!-- lookup parent from repository --> 19 </parent> 20 21 <properties> 22 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 23 <java.version>1.8</java.version> 24 </properties> 25 26 <dependencies> 27 <dependency> 28 <groupId>org.springframework.boot</groupId> 29 <artifactId>spring-boot-starter-web</artifactId> 30 </dependency> 31 32 <dependency> 33 <groupId>org.springframework.boot</groupId> 34 <artifactId>spring-boot-starter-test</artifactId> 35 <scope>test</scope> 36 </dependency> 37 <dependency> 38 <groupId>org.springframework.boot</groupId> 39 <artifactId>spring-boot-starter-thymeleaf</artifactId> 40 </dependency> 41 <dependency> 42 <groupId>org.springframework.boot</groupId> 43 <artifactId>spring-boot-starter-data-jpa</artifactId> 44 </dependency> 45 <dependency> 46 <groupId>org.hsqldb</groupId> 47 <artifactId>hsqldb</artifactId> 48 <scope>runtime</scope> 49 </dependency> 50 </dependencies> 51 52 <build> 53 <plugins> 54 <plugin> 55 <groupId>org.springframework.boot</groupId> 56 <artifactId>spring-boot-maven-plugin</artifactId> 57 </plugin> 58 </plugins> 59 </build> 60</project> 61
エラー内容
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'heloController':Error creating bean with name 'myDataRepository':No bean named 'entityManagerFactory' is defined
回答4件
あなたの回答
tips
プレビュー