niedziela, 9 grudnia 2018

Uploading files in JHipster app

When you trying to add uploading files using this guide walks: https://spring.io/guides/gs/uploading-files/, you may see that kind of errors:


***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of constructor in finbarre.storage.FileSystemStorageService required a bean of type 'finbarre.storage.StorageProperties' that could not be found.


Action:

Consider defining a bean of type 'finbarre.storage.StorageProperties' in your configuration.



To fix it, add @Component annotation to StorageProperties class:



package finbarre.storage;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties("storage")
public class StorageProperties {

    /**
     * Folder location for storing files
     */
    private String location = "upload-dir";

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

}