0
こんにちは、私は私が私のYAML設定ファイルからディレクトリを読み込むことができ、スプリングブートConfigurationPropertiesアノテーションを使用して、単純なファイルアップロードルーチンを実装したnullポインタを与えます 使用法は、JHipsterアプリは
@Service
public class FileSystemStorageService implements StorageService {
private final Logger log = LoggerFactory.getLogger(FileSystemStorageService.class);
private final Path pictureLocation;
@Autowired
public FileSystemStorageService(StorageProperties storageProperties) {
pictureLocation = Paths.get(storageProperties.getUpload());
}
そしてStorageProperties:
:私はYAMLファイルで@Component
@ConfigurationProperties("nutrilife.meals")
public class StorageProperties {
private String upload;
public String getUpload() {
return upload;
}
public void setUpload(String upload) {
this.upload= upload;
}
}
nutrilife:
meals:
upload: /$full_path_to_my_upload_dir
これは、通常の春ブーツランタイムで完璧に動作しますが、問題は、私は私の統合テストを実行しようとすると、それはエラーをスローを開始:それはだよう
java.lang.IllegalStateException: Failed to load ApplicationContext
...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fileSystemStorageService' defined in file [/home/mmaia/git/nutrilife/build/classes/main/com/getnutrilife/service/upload/FileSystemStorageService.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.getnutrilife.service.upload.FileSystemStorageService]: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:279)
...
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.getnutrilife.service.upload.FileSystemStorageService]: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:154)
だから、基本的には試験中のYAMLファイル構成が見えます正しく拾われていない。私は春の新人です。私はこの問題を何時間も抱えていましたが、それを修正する方法は不明です。何か案は?
ありがとうございました。 @value注釈を追加
次働い:@value( "アップロード")ので、このような完全なIMPLはテストでも動作します: @Component @ConfigurationProperties(「nutrilifeを.meals ") パブリッククラスStorageProperties { */ @value(ファイルを格納するための /** * フォルダの場所" "アップロード) プライベート文字列のアップロード。 ... あなたの答えを@Value( "upload")にして、プロパティの上に修正して、正しいものとしてマークしてください。 ありがとうございます。 –
Marcos Maia、ありがとう。 DOne –