トラブル内容
STSの超初心者です。
テキストを使用して勉強しているのですが、mavenベースのプロジェクトで
JPAでH2のDBへ接続するという学習項目に来た時に、
pom.xmlに
lang
1<dependency> 2 <groupId>org.springframework.boot</groupId> 3 <artifactId>spring-boot-starter-jdbc</artifactId> 4</dependency> 5<dependency> 6 <groupId>com.h2database</groupId> 7 <artifactId>h2</artifactId> 8</dependency>
を記載したところで、プロジェクトにビックリマークのようなものがついて、
プロジェクトをビルドすると
コンソールに以下のようなメッセージが出てきてエラーになってしまいます。
エラー
2019-08-09 14:35:13.469 INFO 9372 --- [ main] c.t.springboot.MyBootAppApplication : Starting MyBootAppApplication on NAOKI-PC with PID 9372 (C:\Users\Naoki\Documents\workspace-sts-3.9.2.RELEASE\MyBootApp\target\classes started by Naoki in C:\Users\Naoki\Documents\workspace-sts-3.9.2.RELEASE\MyBootApp)
2019-08-09 14:35:13.485 INFO 9372 --- [ main] c.t.springboot.MyBootAppApplication : No active profile set, falling back to default profiles: default
2019-08-09 14:35:14.346 INFO 9372 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-08-09 14:35:14.409 INFO 9372 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 63ms. Found 1 repository interfaces.
2019-08-09 14:35:14.774 INFO 9372 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$a8474ab6] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-08-09 14:35:15.143 INFO 9372 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-08-09 14:35:15.177 INFO 9372 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-08-09 14:35:15.177 INFO 9372 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.17]
2019-08-09 14:35:15.318 INFO 9372 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-08-09 14:35:15.333 INFO 9372 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1785 ms
2019-08-09 14:35:15.411 WARN 9372 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor 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
2019-08-09 14:35:15.424 INFO 9372 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2019-08-09 14:35:15.440 INFO 9372 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-08-09 14:35:15.440 ERROR 9372 --- [ 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).
すみません、初学者すぎて質問の仕方もボヤッとしてますが、宜しくお願い致します。
各ファイルは以下の通りです。
pom.xml
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 <parent> 6 <groupId>org.springframework.boot</groupId> 7 <artifactId>spring-boot-starter-parent</artifactId> 8 <version>2.1.4.RELEASE</version> 9 <relativePath/> <!-- lookup parent from repository --> 10 </parent> 11 <groupId>com.tsunano.springboot</groupId> 12 <artifactId>MyBootApp</artifactId> 13 <version>0.0.1-SNAPSHOT</version> 14 <name>MyBootApp</name> 15 <description>Sample project for Spring Boot</description> 16 17 <properties> 18 19 <java.version>1.8</java.version> 20 </properties> 21 22 <dependencies> 23 24 <dependency> 25 <groupId>org.springframework.boot</groupId> 26 <artifactId>spring-boot-starter-data-jpa</artifactId> 27 </dependency> 28 29 <dependency> 30 <groupId>com.h2database</groupId> 31 <artifactId>h2</artifactId> 32 </dependency> 33 34 <dependency> 35 <groupId>org.springframework.boot</groupId> 36 <artifactId>spring-boot-starter-web</artifactId> 37 </dependency> 38 39 <dependency> 40 <groupId>org.springframework.boot</groupId> 41 <artifactId>spring-boot-starter-test</artifactId> 42 <scope>test</scope> 43 </dependency> 44 <dependency> 45 <groupId>org.springframework.boot</groupId> 46 <artifactId>spring-boot-starter-thymeleaf</artifactId> 47 </dependency> 48 </dependencies> 49 50 <build> 51 <plugins> 52 <plugin> 53 <groupId>org.springframework.boot</groupId> 54 <artifactId>spring-boot-maven-plugin</artifactId> 55 </plugin> 56 </plugins> 57 </build> 58 59</project> 60
HeloController.java
java
1package com.tsunano.springboot; 2 3import org.springframework.beans.factory.annotation.Autowired; 4import org.springframework.stereotype.Controller; 5import org.springframework.web.bind.annotation.RequestMapping; 6import org.springframework.web.servlet.ModelAndView; 7 8import com.tsunano.springboot.repositories.MyDataRepository; 9 10 11@Controller 12public class HeloController { 13 14 @Autowired 15 MyDataRepository repository; 16 17 @RequestMapping("/") 18 public ModelAndView index(ModelAndView mav) { 19 mav.setViewName("index"); 20 mav.addObject("msg","this is sample content."); 21 Iterable<MyData> list=repository.findAll(); 22 mav.addObject("data",list); 23 return mav; 24 25 } 26 27} 28
MyBootAppApplication.java
java
1package com.tsunano.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} 14
MyData.java
java
1package com.tsunano.springboot; 2 3 4import javax.persistence.Column; 5import javax.persistence.Entity; 6import javax.persistence.GeneratedValue; 7import javax.persistence.GenerationType; 8import javax.persistence.Id; 9import javax.persistence.Table; 10 11@Entity 12@Table(name="mydata") 13 14public class MyData { 15 16 17@Id 18@GeneratedValue(strategy=GenerationType.AUTO) 19@Column 20private long id; 21 22@Column(length=50, nullable=false) 23private String name; 24 25@Column(length=200, nullable=true) 26private String mail; 27 28@Column(nullable=true) 29private Integer age; 30 31@Column(nullable=true) 32private String memo; 33 34 35public long getId() {return id;} 36public void setId(long id) {this.id=id;} 37public String getName() {return name;} 38public void setName(String name) {this.name=name;} 39public String getMail() {return mail;} 40public void setMail(String mail) {this.mail=mail;} 41public Integer getAge() {return age;} 42public void setAge(Integer age) {this.age=age;} 43public String getMemo() {return memo;} 44public void setMemo(String memo) {this.memo=memo;} 45}
MyDataRepository.java
java
1package com.tsunano.springboot.repositories; 2 3 4import com.tsunano.springboot.MyData; 5 6import org.springframework.data.jpa.repository.JpaRepository; 7import org.springframework.stereotype.Repository; 8 9@Repository 10public interface MyDataRepository extends JpaRepository<MyData,Long> { 11 12} 13
試したこと
➀application.propatiesにDBへの接続情報を記載。
→特に変化無し。
➁pom.xmlの書き換え
lang
1<dependency> 2 <groupId>org.hsqldb</groupId> 3 <artifactId>hsqldb</artifactId> 4</dependency>
→ビックリマークは消えました。
そもそもHSQLDBをインストールしていないので、意味がないです。
➂プロジェクトを右クリック→Maven→Update Project
→特に変化無し。
➃Clean
→特に変化無し。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー