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

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

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

JAR(又はJava ARchive)はコンパイルされた複数のJavaバイトコード及び関連ファイルのリソースを一つのファイルに統合したものです。JARファイルはZIPファイルのフォーマットで構築されています。

Java

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

Amazon S3

Amazon S3 (Simple Storage Service)とはアマゾン・ウェブ・サービスが提供するオンラインストレージサービスです。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

Spring Boot

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

Q&A

解決済

2回答

1807閲覧

SpringBootを用いてs3からcsvを読み込みAuroraへINSERTしたい

roco

総合スコア3

JAR

JAR(又はJava ARchive)はコンパイルされた複数のJavaバイトコード及び関連ファイルのリソースを一つのファイルに統合したものです。JARファイルはZIPファイルのフォーマットで構築されています。

Java

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

Amazon S3

Amazon S3 (Simple Storage Service)とはアマゾン・ウェブ・サービスが提供するオンラインストレージサービスです。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

Spring Boot

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

0グッド

0クリップ

投稿2020/05/26 02:52

#概要
やりたいことは表題の通りなのですが、webアプリケーションというような形ではなく、バッチ処理のような動きで処理を行いたいです。
ビルドしたのちjarを実行しようとすると以下のようなエラーが出てしまいます。
どのようにしたらうまく動作しますでしょうか。
ちなみに参考サイトは以下になります。

Spring Data JPAによるデータ登録・更新・削除 その1
#エラーコード
2020-05-26 02:46:55.950 ERROR 5754 --- [ main] o.s.boot.SpringApplication : Application run failed
#コード
App.java

java

1package com.mycompany.app; 2 3import com.amazonaws.services.s3.AmazonS3; 4import com.amazonaws.services.s3.AmazonS3ClientBuilder; 5import com.amazonaws.services.rds.AmazonRDSClientBuilder; 6import com.amazonaws.services.s3.model.S3Object; 7import com.amazonaws.auth.AWSCredentials; 8import com.amazonaws.auth.AWSStaticCredentialsProvider; 9import com.amazonaws.auth.BasicAWSCredentials; 10 11import java.io.BufferedReader; 12import java.io.InputStream; 13import java.io.InputStreamReader; 14 15import java.sql.*; 16import java.util.Properties; 17 18import org.springframework.beans.factory.annotation.Autowired; 19import org.springframework.boot.SpringApplication; 20import org.springframework.boot.CommandLineRunner; 21import org.springframework.boot.autoconfigure.SpringBootApplication; 22import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 23import org.springframework.context.annotation.ComponentScan; 24import org.springframework.data.jpa.repository.JpaRepository; 25 26 27import com.mycompany.app.model.Weather; 28import com.mycompany.app.repository.WeatherRepository; 29 30@EnableAutoConfiguration 31@ComponentScan 32@SpringBootApplication 33public class App implements CommandLineRunner{ 34 @Autowired 35 WeatherRepository weatherRepository; 36 37 public void run(String... strings) throws Exception { 38 //各種定義 39 String clientRegion = "ap-northeast-1"; 40 String bucketName = "バケット名"; 41 String key = "CSV名"; 42 InputStream is = null; 43 BufferedReader br = null; 44 45 //認証情報設定 46 AWSCredentials credentials = new BasicAWSCredentials("アクセスキー","シークレットキー"); 47 48 // クライアント生成(s3とAurora) 49 AmazonS3 client = AmazonS3ClientBuilder.standard() 50 .withCredentials(new AWSStaticCredentialsProvider(credentials)) 51 .withRegion(clientRegion) 52 .build(); 53 54 //オブジェクト取得 55 S3Object s3Object = client.getObject(bucketName, key); 56 57 try { 58 59 is = s3Object.getObjectContent(); 60 br = new BufferedReader(new InputStreamReader(is, "UTF-8")); 61 62 String line; 63 64 System.out.println(is); 65 66 // CSVを1行ずつ読み込んで処理する。 67 while ((line = br.readLine()) != null) { 68 //1レコードをカンマ区切りで配列へ格納 69 String[] data = line.split(",", 0); 70 System.out.println("------------------------------------"); 71 System.out.println(data[0]); //location_id 72 System.out.println(data[1]); //name 73 System.out.println(data[2]); //temp 74 System.out.println(data[3]); //humid 75 76 int location_id = Integer.parseInt(data[0]); 77 String name = data[1]; 78 int temp = Integer.parseInt(data[2]); 79 int humid = Integer.parseInt(data[3]); 80 81 //AURORAへINSERT 82 weatherRepository.save(new Weather(location_id,name,temp,humid)); 83 84 } 85 86 } finally { 87 if (is != null) { 88 is.close(); 89 } 90 if (br != null) { 91 br.close(); 92 } 93 } 94 } 95 public static void main( String[] args ) 96 { 97 SpringApplication.run(App.class, args); 98 } 99} 100

Weather.java

java

1package com.mycompany.app.model; 2 3import java.sql.Timestamp; 4import java.io.Serializable; 5import java.util.Date; 6 7import javax.persistence.Entity; 8import javax.persistence.Column; 9import javax.persistence.GeneratedValue; 10import javax.persistence.GenerationType; 11import javax.persistence.Id; 12import javax.persistence.Table; 13 14import lombok.AllArgsConstructor; 15import lombok.Data; 16import lombok.NoArgsConstructor; 17 18@Entity 19@Data 20@Table(name="weather") 21@NoArgsConstructor 22@AllArgsConstructor 23public class Weather{ 24 @Id 25 @Column(name="id") 26 @GeneratedValue(strategy=GenerationType.IDENTITY) 27 private Integer id; 28 29 @Column(nullable = true) 30 private Integer locationId; 31 32 @Column(nullable = true) 33 private String name; 34 35 @Column(nullable = true) 36 private Integer temperature; 37 38 @Column(nullable = true) 39 private Integer humidity; 40 41 @Column(nullable = true) 42 private Timestamp date_time; 43 44 public Weather(int locationId, String name, int temperature, int humidity) 45 { 46 this.locationId = locationId; 47 this.name = name; 48 this.temperature = temperature; 49 this.humidity = humidity; 50 51 } 52}

WeatherRepository.java

java

1package com.mycompany.app.repository; 2 3import org.springframework.data.jpa.repository.JpaRepository; 4 5import com.mycompany.app.model.Weather; 6 7public interface WeatherRepository extends JpaRepository<Weather, Integer> { 8 9}

pom.xml

java

1<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 3 4 <modelVersion>4.0.0</modelVersion> 5 6 <parent> 7 <groupId>org.springframework.boot</groupId> 8 <artifactId>spring-boot-starter-parent</artifactId> 9 <version>2.2.6.RELEASE</version> 10 <relativePath/> <!-- lookup parent from repository --> 11 </parent> 12 13 <groupId>com.mycompany.app</groupId> 14 <artifactId>my-app</artifactId> 15 <packaging>jar</packaging> 16 <version>1.0-SNAPSHOT</version> 17 18 <build> 19 <plugins> 20 <plugin> 21 <groupId>org.apache.maven.plugins</groupId> 22 <artifactId>maven-assembly-plugin</artifactId> 23 <version>3.0.0</version> 24 <configuration> 25 <descriptorRefs> 26 <descriptorRef>jar-with-dependencies</descriptorRef> 27 </descriptorRefs> 28 <archive> 29 <manifest> 30 <mainClass>com.mycompany.app.App</mainClass> 31 </manifest> 32 </archive> 33 </configuration> 34 <executions> 35 <execution> 36 <phase>package</phase> 37 <goals> 38 <goal>single</goal> 39 </goals> 40 </execution> 41 </executions> 42 </plugin> 43 <plugin> 44 <groupId>org.springframework.boot</groupId> 45 <artifactId>spring-boot-maven-plugin</artifactId> 46 <executions> 47 <execution> 48 <goals> 49 <goal>repackage</goal> 50 </goals> 51 </execution> 52 </executions> 53 </plugin> 54 </plugins> 55 </build> 56 57 <dependencies> 58 <dependency> 59 <groupId>com.amazonaws</groupId> 60 <artifactId>aws-java-sdk-bom</artifactId> 61 <version>1.11.327</version> 62 <type>pom</type> 63 <scope>import</scope> 64 </dependency> 65 <dependency> 66 <groupId>com.amazonaws</groupId> 67 <artifactId>aws-java-sdk-s3</artifactId> 68 <version>1.11.330</version> 69 </dependency> 70 <dependency> 71 <groupId>com.amazonaws</groupId> 72 <artifactId>aws-java-sdk-rds</artifactId> 73 <version>1.11.330</version> 74 </dependency> 75 <dependency> 76 <groupId>org.apache.commons</groupId> 77 <artifactId>commons-io</artifactId> 78 <version>1.3.2</version> 79 </dependency> 80 <dependency> 81 <groupId>org.postgresql</groupId> 82 <artifactId>postgresql</artifactId> 83 <version>9.4.1207</version> 84 </dependency> 85 <dependency> 86 <groupId>org.projectlombok</groupId> 87 <artifactId>lombok</artifactId> 88 <version>1.18.8</version> 89 <scope>provided</scope> 90 </dependency> 91 <dependency> 92 <groupId>org.springframework.boot</groupId> 93 <artifactId>spring-boot-starter-data-jpa</artifactId> 94 </dependency> 95 </dependencies> 96 97</project>

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

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

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

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

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

guest

回答2

0

ベストアンサー

Auroraへ接続するための設定はどちらに記載されていますか?
こちらの質問に貼り付けられているコード以外に記載されていましたら、
そちらも貼り付けていただけるとアドバイスできるかもしれません。
未設定でしたら、以下のドキュメントを参考に記載してみてください。
https://docs.aws.amazon.com/ja_jp/AmazonRDS/latest/UserGuide/UsingWithRDS.IAMDBAuth.Connecting.Java.html#UsingWithRDS.IAMDBAuth.Connecting.Java.AuthToken.Connect

また、Application run failedというエラーが発生した原因が、
それ以降の行にスタックトレースとして出力されていましたら、
こちらも貼り付けていただけるとアドバイスできるかもしれません。

投稿2020/05/29 04:15

ReinforceII

総合スコア7

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

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

0

Springには詳しくないので的はずれなことを言ってたら申し訳ないですが、
参考サイトのxmlと比べるにcom.h2databaseを指定してなさそうな気がするのですがそこは問題ないのでしょうか。


また、この質問に対する回答ではないのですが、参考までに下記のようなことも行えます。
Amazon S3 バケットのテキストファイルから Amazon Aurora MySQL DB クラスターへのデータのロード

【新機能】Amazon AuroraにS3からの直接データロード機能が追加。

投稿2020/05/26 06:22

yu_1985

総合スコア7447

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問