title: Spring Boot can't autowire @ConfigurationProperties
body: <p>Here is my <code>FileStorageProperties</code> class:</p>
  
  <pre><code> @Data
   @ConfigurationProperties(prefix = "file")
   public class FileStorageProperties {
         private String uploadDir;
   }
  </code></pre>
  
  <p>This gives me saying : <em>not registered via @enableconfigurationproperties or marked as spring component</em>.</p>
  
  <p>And here is my <code>FileStorageService</code> :</p>
  
  <pre><code>@Service
  public class FileStorageService {
  
  private final Path fileStorageLocation;
  
  @Autowired
  public FileStorageService(FileStorageProperties fileStorageProperties) {
      this.fileStorageLocation = Paths.get(fileStorageProperties.getUploadDir())
              .toAbsolutePath().normalize();
  
      try {
          Files.createDirectories(this.fileStorageLocation);
      } catch (Exception ex) {
          throw new FileStorageException("Could not create the directory where the uploaded files will be stored.", ex);
      }
  }
  
  public String storeFile(MultipartFile file) {
      // Normalize file name
      String fileName = StringUtils.cleanPath(file.getOriginalFilename());
  
      try {
          // Check if the file's name contains invalid characters
          if(fileName.contains("..")) {
              throw new FileStorageException("Sorry! Filename contains invalid path sequence " + fileName);
          }
  
          // Copy file to the target location (Replacing existing file with the same name)
          Path targetLocation = this.fileStorageLocation.resolve(fileName);
          Files.copy(file.getInputStream(), targetLocation, StandardCopyOption.REPLACE_EXISTING);
  
          return fileName;
      } catch (IOException ex) {
          throw new FileStorageException("Could not store file " + fileName + ". Please try again!", ex);
      }
  }
  
  public Resource loadFileAsResource(String fileName) {
      try {
          Path filePath = this.fileStorageLocation.resolve(fileName).normalize();
          Resource resource = new UrlResource(filePath.toUri());
          if(resource.exists()) {
              return resource;
          } else {
              throw new MyFileNotFoundException("File not found " + fileName);
          }
      } catch (MalformedURLException ex) {
          throw new MyFileNotFoundException("File not found " + fileName, ex);
      }
  }
  }
  </code></pre>
  
  <p>This gives me error saying : <em>could not autowire no beans of type found</em>.</p>
  
  <p>And here is my project structure :</p>
  
  <p><a href="https://i.stack.imgur.com/F6IZq.png" rel="noreferrer"><img src="https://i.stack.imgur.com/F6IZq.png" alt="Spring Boot can&#39;t autowire @ConfigurationProperties - project structure"></a></p>
  
  <p>And when I try to run it, it gives me :</p>
  
  <hr>
  
  <p>APPLICATION FAILED TO START</p>
  
  <p>Description:</p>
  
  <p>Parameter 0 of constructor in com.mua.cse616.Service.FileStorageService required a bean of type 'com.mua.cse616.Property.FileStorageProperties' that could not be found.</p>
  
  <p>The injection point has the following annotations:
      - @org.springframework.beans.factory.annotation.Autowired(required=true)</p>
  
  <p>Action:</p>
  
  <p>Consider defining a bean of type 'com.mua.cse616.Property.FileStorageProperties' in your configuration.</p>
  
  <hr>
  
  <p><strong>How can I resolve this?</strong></p>