大学の授業でJavaの勉強をしています。
SpringbootでWebアプリケーションを作ってみようと作業を進めている際にエラーがでて全く先に進めなかったので解決策の書き溜め。
EclipeseでSpringbootを使用して実行を押すと下記のエラーがでて停止してしまう。
1 2 3 4 5 6 7 8 9 10 11 12 |
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). |
解決策
先に2つの解決策を書いておきます。
私は2つ目の方でとりあえず先に進めました。
MySQLを起動させて接続情報を追加する
src/main/resourcesディレクトリの配下に, application.ymlまたはapplication.propertiesというファイルがあります。
そこにMySQLへの接続情報を追加してください。
h2.databaseを pom.xmlに追加する
すぐにMySQLを使う必要がない。とりあえず起動させたいという時には設定の変更ではなく組み込みのデータベースを使うのも手です。下記をpom.xmlに追加して実行することでも起動するようになります。
1 2 3 4 5 |
<dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <scope>runtime</scope> </dependency> |
h2を追加して実行したところ問題なく起動した。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ [32m :: Spring Boot :: [39m [2m (v2.7.0)[0;39m [2m2022-06-22 21:30:46.057[0;39m [32m INFO[0;39m [35m19332[0;39m [2m---[0;39m [2m[main][0;39m [36mcom.example.demo.DemoSpringApplication [0;39m [2m:[0;39m Starting DemoSpringApplication using Java 16.0.1 on DESKTOP-5ATNOFN with PID 19332 (C:\pleiades\workspace\demoSpring\target\classes started by yahata in C:\pleiades\workspace\demoSpring) [2m2022-06-22 21:30:46.060[0;39m [32m INFO[0;39m [35m19332[0;39m [2m---[0;39m [2m[main][0;39m [36mcom.example.demo.DemoSpringApplication [0;39m [2m:[0;39m No active profile set, falling back to 1 default profile: "default" [2m2022-06-22 21:30:47.279[0;39m [32m INFO[0;39m [35m19332[0;39m [2m---[0;39m [2m[main][0;39m [36m.s.d.r.c.RepositoryConfigurationDelegate[0;39m [2m:[0;39m Bootstrapping Spring Data JPA repositories in DEFAULT mode. [2m2022-06-22 21:30:47.303[0;39m [32m INFO[0;39m [35m19332[0;39m [2m---[0;39m [2m[main][0;39m [36m.s.d.r.c.RepositoryConfigurationDelegate[0;39m [2m:[0;39m Finished Spring Data repository scanning in 6 ms. Found 0 JPA repository interfaces. [2m2022-06-22 21:30:47.822[0;39m [32m INFO[0;39m [35m19332[0;39m [2m---[0;39m [2m[main][0;39m [36mo.s.b.w.embedded.tomcat.TomcatWebServer [0;39m [2m:[0;39m Tomcat initialized with port(s): 8080 (http) [2m2022-06-22 21:30:47.834[0;39m [32m INFO[0;39m [35m19332[0;39m [2m---[0;39m [2m[main][0;39m [36mo.apache.catalina.core.StandardService [0;39m [2m:[0;39m Starting service [Tomcat] [2m2022-06-22 21:30:47.834[0;39m [32m INFO[0;39m [35m19332[0;39m [2m---[0;39m [2m[main][0;39m [36morg.apache.catalina.core.StandardEngine [0;39m [2m:[0;39m Starting Servlet engine: [Apache Tomcat/9.0.63] [2m2022-06-22 21:30:47.953[0;39m [32m INFO[0;39m [35m19332[0;39m [2m---[0;39m [2m[main][0;39m [36mo.a.c.c.C.[Tomcat].[localhost].[/] [0;39m [2m:[0;39m Initializing Spring embedded WebApplicationContext [2m2022-06-22 21:30:47.953[0;39m [32m INFO[0;39m [35m19332[0;39m [2m---[0;39m [2m[main][0;39m [36mw.s.c.ServletWebServerApplicationContext[0;39m [2m:[0;39m Root WebApplicationContext: initialization completed in 1737 ms [2m2022-06-22 21:30:48.103[0;39m [32m INFO[0;39m [35m19332[0;39m [2m---[0;39m [2m[main][0;39m [36mcom.zaxxer.hikari.HikariDataSource [0;39m [2m:[0;39m HikariPool-1 - Starting... [2m2022-06-22 21:30:48.358[0;39m [32m INFO[0;39m [35m19332[0;39m [2m---[0;39m [2m[main][0;39m [36mcom.zaxxer.hikari.HikariDataSource [0;39m [2m:[0;39m HikariPool-1 - Start completed. [2m2022-06-22 21:30:48.412[0;39m [32m INFO[0;39m [35m19332[0;39m [2m---[0;39m [2m[main][0;39m [36mo.hibernate.jpa.internal.util.LogHelper [0;39m [2m:[0;39m HHH000204: Processing PersistenceUnitInfo [name: default] [2m2022-06-22 21:30:48.483[0;39m [32m INFO[0;39m [35m19332[0;39m [2m---[0;39m [2m[main][0;39m [36morg.hibernate.Version [0;39m [2m:[0;39m HHH000412: Hibernate ORM core version 5.6.9.Final [2m2022-06-22 21:30:48.720[0;39m [32m INFO[0;39m [35m19332[0;39m [2m---[0;39m [2m[main][0;39m [36mo.hibernate.annotations.common.Version [0;39m [2m:[0;39m HCANN000001: Hibernate Commons Annotations {5.1.2.Final} [2m2022-06-22 21:30:48.916[0;39m [32m INFO[0;39m [35m19332[0;39m [2m---[0;39m [2m[main][0;39m [36morg.hibernate.dialect.Dialect [0;39m [2m:[0;39m HHH000400: Using dialect: org.hibernate.dialect.H2Dialect [2m2022-06-22 21:30:49.149[0;39m [32m INFO[0;39m [35m19332[0;39m [2m---[0;39m [2m[main][0;39m [36mo.h.e.t.j.p.i.JtaPlatformInitiator [0;39m [2m:[0;39m HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform] [2m2022-06-22 21:30:49.160[0;39m [32m INFO[0;39m [35m19332[0;39m [2m---[0;39m [2m[main][0;39m [36mj.LocalContainerEntityManagerFactoryBean[0;39m [2m:[0;39m Initialized JPA EntityManagerFactory for persistence unit 'default' [2m2022-06-22 21:30:49.189[0;39m [33m WARN[0;39m [35m19332[0;39m [2m---[0;39m [2m[main][0;39m [36mJpaBaseConfiguration$JpaWebConfiguration[0;39m [2m:[0;39m spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning [2m2022-06-22 21:30:49.457[0;39m [33m WARN[0;39m [35m19332[0;39m [2m---[0;39m [2m[main][0;39m [36mion$DefaultTemplateResolverConfiguration[0;39m [2m:[0;39m Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration) [2m2022-06-22 21:30:49.574[0;39m [32m INFO[0;39m [35m19332[0;39m [2m---[0;39m [2m[main][0;39m [36mo.s.b.w.embedded.tomcat.TomcatWebServer [0;39m [2m:[0;39m Tomcat started on port(s): 8080 (http) with context path '' [2m2022-06-22 21:30:49.586[0;39m [32m INFO[0;39m [35m19332[0;39m [2m---[0;39m [2m[main][0;39m [36mcom.example.demo.DemoSpringApplication [0;39m [2m:[0;39m Started DemoSpringApplication in 6.001 seconds (JVM running for 7.086) |
PythonとRuby、あとRustしか触ってこなかった人間にはEclipseの世界が広すぎる。。
ちょっとずつ覚えていこう。
じゃあね~。