実現したいこと
アプリを実行したいのですが、MySQLのエラーが出てしまいます。
前提
ここに質問の内容を詳しく書いてください。
Javaで文字を入力すると画面上に表示されるだけの簡単なアプリを作成している途中です。MySQLと連携する途中でエラーが出てしまい、Javaを習い始めて間もないので解決方法がさっぱりわからないです。
発生している問題・エラーメッセージ
エラーメッセージ FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':FirstAppApplication.main()'. > Could not resolve all files for configuration ':runtimeClasspath'. > Could not find mysql:mysql-connector-java:. Required by: project : * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. * Get more help at https://help.gradle.org BUILD FAILED in 580ms
build.gradle
1plugins { 2 id 'java' 3 id 'org.springframework.boot' version '2.7.12' 4 id 'io.spring.dependency-management' version '1.0.15.RELEASE' 5} 6 7group = 'in.techcamp' 8version = '0.0.1-SNAPSHOT' 9sourceCompatibility = '17' 10 11repositories { 12 mavenCentral() 13} 14 15dependencies { 16 implementation 'org.springframework.boot:spring-boot-starter-web' 17 testImplementation 'org.springframework.boot:spring-boot-starter-test' 18 implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' 19 implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.2.2' 20 runtimeOnly 'mysql:mysql-connector-java' 21 compileOnly 'org.projectlombok:lombok' 22 annotationProcessor 'org.projectlombok:lombok' 23} 24 25tasks.named('test') { 26 useJUnitPlatform() 27}
Postcontroller
1 2package in.techcamp.firstapp; 3 4import org.springframework.stereotype.Controller; 5import org.springframework.ui.Model; 6import org.springframework.web.bind.annotation.GetMapping; 7 8import java.util.List; 9 10@Controller 11public class PostController { 12 @GetMapping("/hello") 13 public String showHello(Model model) { 14 var sampleText = "サンプルテキスト"; 15 model.addAttribute("sampleText", sampleText); 16 return "hello"; 17 } 18 19 @GetMapping 20 public String showList(Model model) { 21 var postList = List.of( 22 new PostEntity(1, "投稿1"), 23 new PostEntity(2, "投稿2"), 24 new PostEntity(3, "投稿3") 25 ); 26 model.addAttribute("postList", postList); 27 return "index"; 28 } 29}
application.prorerties
1 2spring.sql.init.mode=always 3spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver 4spring.datasource.url=jdbc:mysql://localhost:3306/first_app_java 5spring.datasource.username=root 6spring.datasource.password= 7 8schema.sql 9 10CREATE TABLE IF NOT EXISTS posts ( 11 id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT, 12 memo VARCHAR(256) NOT NULL 13);
試したこと
mesqlが見つからない的な内容のエラーが出ているのはわかりました。解決策を検索してみたのですが、どれをみてもよく分からなくて何もできていないです。
回答1件
あなたの回答
tips
プレビュー