私はスプリングブート1.5.7.RELEASEを使用していますが、application.ymlファイルの値をクラスに注入しようとしていますが、値は常にnullになります。値は私のクラスでロードされます。スプリングブートアプリケーション@Valueプロパティは常にnullを返します
私は、次のエラーを取得しています、私の基本パッケージで
package com.mypackage;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
VideoTranscoder vt = new VideoTranscoder();
vt.createJob();
}
}
私のクラス、
package com.mypackage;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.elastictranscoder.AmazonElasticTranscoder;
import com.amazonaws.services.elastictranscoder.AmazonElasticTranscoderClientBuilder;
import com.amazonaws.services.elastictranscoder.model.CreateJobOutput;
import com.amazonaws.services.elastictranscoder.model.CreateJobRequest;
import com.amazonaws.services.elastictranscoder.model.JobInput;
//@Component
public class VideoTranscoder {
private static final String PIPELINE_ID = "xxxxxxxxx-xxxx";
private static final String INPUT_KEY = "video.avi";
private static final String OUTPUT_KEY = "transcoded_video.mp4";
private static final String PRESET_ID = "1351620000001-000061";
// @Value("${s3.accessKey}")
// private String accessKey;
@Value("Hello")
private String accessKey;
@Value("${s3.secretKey}")
private String secretKey;
public void createJob() {
System.out.println("SECRETKEY: " + secretKey);
System.out.println("ACCESSKEY: " + accessKey);
BasicAWSCredentials creds = new BasicAWSCredentials(accessKey, secretKey);
AmazonElasticTranscoder amazonElasticTranscoder = AmazonElasticTranscoderClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(creds)).withRegion(Regions.US_EAST_1).build();
JobInput input = new JobInput().withKey(INPUT_KEY);
CreateJobOutput output = new CreateJobOutput().withKey(OUTPUT_KEY).withPresetId(PRESET_ID);
CreateJobRequest createJobRequest = new CreateJobRequest().withPipelineId(PIPELINE_ID).withInput(input)
.withOutputs(output);
amazonElasticTranscoder.createJob(createJobRequest);
System.out.println("DONE!");
}
}
マイapplication.yml、
s3:
accessKey: XXXXXXXXXXXXXXXXXXXX
secretKey: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
以下のように私は、アプリケーションクラスを持っています、
SECRETKEY: null
ACCESSKEY: null
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: java.lang.IllegalArgumentException: Access key cannot be null.
at com.amazonaws.auth.BasicAWSCredentials.<init>(BasicAWSCredentials.java:37)
at com.mypackage.VideoTranscoder.createJob(VideoTranscoder.java:38)
at com.mypackage.Application.main(Application.java:12)
... 8 more
なぜ、常にNULLを返すのですか?
あなたのご意見をお待ちしています。
あなたは '@ Component'注釈をコメントアウト。 – teppic
@Componentをコメントアウトしても同じ結果が得られない – SST