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

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

新規登録して質問してみよう
ただいま回答率
85.50%
Spring Boot

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

Q&A

解決済

1回答

10015閲覧

Spring Bootを使用しweb上に”HelloWorld”を表示させたいがlocalhostにアクセスできません

eitoyoshida

総合スコア1

Spring Boot

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

0グッド

0クリップ

投稿2021/08/19 07:35

前提・実現したいこと

Java初心者です、初めて質問させていただきます
webアプリケーションを作成したいと思い
https://medium-company.com/spring-boot-thymeleaf/
こちらのサイトを参考に"HelloWorld"を表示させようとしたところ


このサイトにアクセスできませんlocalhost で接続が拒否されました。
次をお試しください

接続を確認する
プロキシとファイアウォールを確認する
ERR_CONNECTION_REFUSED


上記の通りlocalhostにアクセスできません

またプロジェクトの実行を行った際コンソールの上部に
<終了>springSample-1 -SpringSample1Application[Spring Boot アプリケーション]
と表示されます。

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

. ____ _ __ _ _
/\ / ' __ _ () __ __ _ \ \ \
( ( )_
_ | '_ | '| | ' / ` | \ \ \
/ __)| |)| | | | | || (
| | ) ) ) )
' || .__|| ||| |_, | / / / /
=========|
|==============|
/=////
 :: Spring Boot ::   (v2.5.3)

2021-08-19 16:05:32.209  INFO 4616 --- [ main] c.example.demo.SpringSample1Application  : Starting SpringSample1Application using Java 11.0.11 on SICPC-2021-01 with PID 4616 (C:\Users\SIC\Desktop\アプリケーション作成課題Java\springSample-1\bin\main started by SIC in C:\Users\SIC\Desktop\アプリケーション作成課題Java\springSample-1)
2021-08-19 16:05:32.211  INFO 4616 --- [ main] c.example.demo.SpringSample1Application  : No active profile set, falling back to default profiles: default
2021-08-19 16:05:32.615  INFO 4616 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2021-08-19 16:05:32.626  INFO 4616 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 5 ms. Found 0 JPA repository interfaces.
2021-08-19 16:05:32.955  INFO 4616 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-08-19 16:05:32.962  INFO 4616 --- [ main] o.apache.catalina.core.StandardService  : Starting service [Tomcat]
2021-08-19 16:05:32.962  INFO 4616 --- [ main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.50]
2021-08-19 16:05:33.043  INFO 4616 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/]  : Initializing Spring embedded WebApplicationContext
2021-08-19 16:05:33.044  INFO 4616 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 801 ms
2021-08-19 16:05:33.081  WARN 4616 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Unsatisfied dependency expressed through method 'dataSourceScriptDatabaseInitializer' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
2021-08-19 16:05:33.082  INFO 4616 --- [ main] o.apache.catalina.core.StandardService  : Stopping service [Tomcat]
2021-08-19 16:05:33.095  INFO 4616 --- [ main] ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-08-19 16:05:33.105 ERROR 4616 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter  :


APPLICATION FAILED TO START


Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class

Action:

Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

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

言葉足らずですいません。
よろしくお願いい達します。

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

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

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

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

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

ishina_yum

2021/08/19 07:53

それで一体何を知りたいのでしょう?
m.ts10806

2021/08/19 08:00

コンソールの表示内容だけ提示されても「出てる情報通りでしょうね」くらいしか他者には応えられません。コピペで再現できる程度に情報を提示してください
eitoyoshida

2021/08/20 00:06

ご教授ありがとうございます。 コンソール画面の内容をしっかり自分で理解できるよう精進します。
m.ts10806

2021/08/20 00:28

質問は編集できます
eitoyoshida

2021/08/20 02:21 編集

今回の件は無事解決できましたので 次回ご質問させていいただく際はコピペで再現できるよう コードも載せ投稿するようにします。 また機会があればよろしくお願いいたします。 ありがとうございました。
guest

回答1

0

ベストアンサー

application.propertiesのDB設定は、正しいでしょうか?
ログに「データソースの構成に失敗しました」と出ているので、DB接続ができず、Spring Bootが落ちています。

単純に動かすだけなら組み込みDBを使うと楽なので、dependencies内にH2 DBを追加すると、動くようになります。

xml

1<!-- pom.xmlの場合 --> 2<dependencies> 3 <dependency> 4 <groupId>com.h2database</groupId> 5 <artifactId>h2</artifactId> 6 <scope>runtime</scope> 7 </dependency>

gradle

1// build.gradleの場合 2dependencies { 3 runtimeOnly 'com.h2database:h2'

※H2 DBを使う場合、application.propertiesのMySQLやPostgreSQLの設定は、コメントアウトするか削除ください

投稿2021/08/19 23:54

KT001

総合スコア611

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

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

eitoyoshida

2021/08/20 02:18

ご回答ありがとうございます。 ご指示いただいた通り組み込みDBを使用し無事表示させることができました。
KT001

2021/08/20 09:18

無事動いて良かったです。 最初は大変かもしれませんが、慣れるとポイントが分かってくると思うので、安心して試してみてください。(また機会があれば、回答させて頂きます)
eitoyoshida

2021/08/23 04:40

ありがとうございます。 MySQLにも無事つなぐことができました。 また、機会があればよろしくお願いいたします。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問