質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

Q&A

解決済

2回答

8830閲覧

springbootにて「creatingbeanerror」が発生し、起動に失敗する

kinu221

総合スコア26

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

0グッド

0クリップ

投稿2019/05/02 07:00

編集2019/05/02 12:52

前提・実現したいこと

springbootにてError creating beanが発生していますので、トラブルシュートして起動できるようにしたい。

個人で勉強のため、STSでSpringBootを使用してCRUDシステムを開発しています。
サーバーを起動しようとすると下記のエラーが発生して、うまくいきません。
個人で解決できませんでしたので、先達の方にアドバイスを頂けると幸いです。
宜しくお願い致します。

発生している問題・エラーメッセージ

Communications link failure

BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource

該当のソースコード

applicationproperties

1spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver 2spring.datasource.url=jdbc:mysql://localhost:3306/person_db 3spring.datasource.username=root 4spring.datasource.password=

PersonService

1package com.example.person.service; 2 3import java.util.List; 4 5import org.springframework.beans.factory.annotation.Autowired; 6import org.springframework.stereotype.Service; 7 8import com.example.person.entity.PersonEntity; 9import com.example.person.repository.PersonRepository; 10 11@Service 12public class PersonService { 13 14 @Autowired 15 private PersonRepository personRepository; 16 17 public List<PersonEntity> findAll() { 18 return personRepository.findAll(); 19 } 20 21 public PersonEntity findOne(long id) { 22 return personRepository.findById(id).orElse(null); 23 } 24 25 public PersonEntity save(PersonEntity person) { 26 return personRepository.save(person); 27 } 28 29 public void delete(long id) { 30 personRepository.deleteById((long) id); 31 } 32}

Entity

1package com.example.person.entity; 2 3import javax.persistence.Entity; 4import javax.persistence.GeneratedValue; 5import javax.persistence.GenerationType; 6import javax.persistence.Id; 7import javax.persistence.Table; 8import javax.validation.constraints.Max; 9import javax.validation.constraints.Min; 10import javax.validation.constraints.NotEmpty; 11import javax.validation.constraints.NotNull; 12import javax.validation.constraints.Size; 13 14@Entity 15@Table(name="person") 16public class PersonEntity { 17 @Id 18 @GeneratedValue(strategy = GenerationType.IDENTITY) 19 private long id; 20 @NotEmpty 21 private String name; 22 @NotNull 23 @Min(value = 0) 24 @Max(value = 150) 25 private int age; 26 @Size(max = 20) 27 private String belong; 28 private String workplace; 29 30 public long getId() { 31 return id; 32 } 33 public void setId(long id) { 34 this.id = id; 35 } 36 public String getName() { 37 return name; 38 } 39 public void setName(String name) { 40 this.name = name; 41 } 42 public int getAge() { 43 return age; 44 } 45 public void setAge(int age) { 46 this.age = age; 47 } 48 public String getBelong() { 49 return belong; 50 } 51 public void setTeam(String belong) { 52 this.belong = belong; 53 } 54 public String getWorkplace() { 55 return workplace; 56 }

pom

1<dependencies> 2 <dependency> 3 <groupId>org.springframework.boot</groupId> 4 <artifactId>spring-boot-starter-data-jpa</artifactId> 5 </dependency> 6 <dependency> 7 <groupId>org.springframework.boot</groupId> 8 <artifactId>spring-boot-starter-thymeleaf</artifactId> 9 </dependency> 10 <dependency> 11 <groupId>org.springframework.boot</groupId> 12 <artifactId>spring-boot-starter-web</artifactId> 13 </dependency> 14 15 <dependency> 16 <groupId>org.springframework.boot</groupId> 17 <artifactId>spring-boot-devtools</artifactId> 18 <scope>runtime</scope> 19 </dependency> 20 <dependency> 21 <groupId>com.h2database</groupId> 22 <artifactId>h2</artifactId> 23 <scope>runtime</scope> 24 </dependency> 25 <dependency> 26 <groupId>org.springframework.boot</groupId> 27 <artifactId>spring-boot-starter-test</artifactId> 28 <scope>test</scope> 29 </dependency> 30 <dependency> 31 <groupId>mysql</groupId> 32 <artifactId>mysql-connector-java</artifactId> 33 <scope>runtime</scope> 34 </dependency> 35 <dependency> 36 <groupId>nz.net.ultraq.thymeleaf</groupId> 37 <artifactId>thymeleaf-layout-dialect</artifactId> 38 </dependency> 39 </dependencies>

該当しそうなソースコードのみを挙げています。
他にもありますので、必要な時はご連絡ください。

試したこと

ネットで調べて下記の内容に変更するとトラブルシュートできるとあり、試しましたが解決できませんでした。
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
アノテーションの見直し。

補足情報(FW/ツールのバージョンなど)

STS 4.2.0
SpringBoot
phpmyadmin

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

記載されたエラーメッセージでは、entityManagerFactoryのbean作成に失敗した、と出ていますね。

entityManagerFactoryのソースを見直してみてはいかがでしょうか?

見当違いの回答でしたね。
こちらの情報が参考になりませんでしょうか?
https://teratail.com/questions/110174

前提条件として、データベースは起動しており、jdbcで指定しているデータベースにユーザーでログインできる状態でしょうか?

投稿2019/05/02 08:28

編集2019/05/02 08:34
takyafumin

総合スコア2335

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

kinu221

2019/05/02 11:48

ご回答ありがとうございます。 データベースは起動しており、propertiesにデータベースの設定をしていますので、DB接続設定はできていると思います。(記載ミスなどがなければ。) @Columnは記載していますので、紐付けもできていると思います。
kinu221

2019/05/04 13:44

サーバーの起動はできるようになりましたが、初期表示画面にアクセスすると下記エラーが表示されます。原因がわからなくアドバイスを頂けると幸いです。 com.example.person.PersonApplication : No active profile set, falling back to default profiles: default .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG' .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode. .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 122ms. Found 1 repository interfaces. trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$54f27dce] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) o.apache.catalina.core.StandardService : Starting service [Tomcat] org.apache.catalina.core.StandardEngine : Starting Servlet engine: Initializing Spring embedded WebApplicationContext o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 6751 ms Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary. o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [ name: default ...] org.hibernate.Version : HHH000412: Hibernate Core org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting... com.zaxxer.hikari.util.DriverDataSource : Registered driver with driverClassName=com.mysql.jdbc.Driver was not found, trying direct instantiation. com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization. com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure 2019-05-04 22:21:44.770 WARN 11876 --- [ restartedMain] o.h.e.j.e.i.JdbcEnvironmentInitiator : HHH000342: Could not obtain connection to query metadata : Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. 2019-05-04 22:21:44.820 INFO 11876 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect 2019-05-04 22:22:17.386 ERROR 11876 --- [nio-8080-exec-3] o.h.engine.jdbc.spi.SqlExceptionHelper : Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. 2019-05-04 22:22:17.557 ERROR 11876 --- [nio-8080-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection] with root cause
guest

0

自己解決

コードの記載ミスでそれを修正するとサーバーの起動はできるようになりました。

投稿2019/05/05 14:20

kinu221

総合スコア26

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問