스프링 부트 응용 프로그램에서 @Autowired
을 사용하여 일부 속성을 초기화합니다. 원시 데이터 형식을 초기화하는 방법을 알고 있지만 개체를 초기화하는 방법을 모르겠습니다.application.properties를 사용하여 객체를 초기화하십시오.
그건 내 Component
:
@Component
@ConfigurationProperties(prefix = "bitmovin.bitmovin")
public class BitmovinConfig {
private S3InputConfig S3InputConfig = new S3InputConfig();
private int threadPoolSize;
private ArrayList<String> testFiles;
public BitmovinConfig() {
}
public S3InputConfig getS3InputConfig() {
return S3InputConfig;
}
public void setS3InputConfig(S3InputConfig s3InputConfig) {
S3InputConfig = s3InputConfig;
}
public int getThreadPoolSize() {
return threadPoolSize;
}
public void setThreadPoolSize(int threadPoolSize) {
this.threadPoolSize = threadPoolSize;
}
public ArrayList<String> getTestFiles() {
return testFiles;
}
public void setTestFiles(ArrayList<String> testFiles) {
this.testFiles = testFiles;
}
}
그리고 내 application.properties
파일입니다 :
bitmovin.bitmovin.threadPoolSize = 30
bitmovin.bitmovin.S3InputConfig = ??
bitmovin.bitmovin.testFiles= ??
가 어떻게 객체 나 application.properties
의 목록을 초기화 할 수 있습니다?
는
오브젝트, 나 자신을 작성하지 않았다, 내가 초기화 할 UPDATE : 목록은
public class S3OutputConfig {
@Expose
public String name;
@Expose
public S3Region region;
@Expose
public String accessKey;
@Expose
public String secretKey;
@Expose
public String bucket;
@Expose
public String prefix;
@Expose
public boolean makePublic;
}
목록에 제안 해 주셔서 감사합니다. 꽤 괜찮습니다.하지만 'bitmovin.bitmovin.s3-input-config.bucket = awesome-video'를 사용하여 객체 속성을 설정하면 여전히 null입니다. – TheDoctor
질문을 객체의 클래스로 업데이트했습니다. – TheDoctor
전체 개체를 초기화 할 수 없으므로 예제에서 수행 한 것처럼 다양한 필드를 초기화해야합니다. 끝에'.name '이 있음을 주목하십시오. 그'@ Expose'가 무엇인지 모르겠지만 바인딩이 작동하려면 getter/setter가 필요합니다. –