spring-content icon indicating copy to clipboard operation
spring-content copied to clipboard

Unable to Use Azure Data Storage in Springboot

Open uhexos opened this issue 1 year ago • 3 comments

Describe the bug Attempting to use the spring-content-azure-storage package results in error below on application start Parameter 1 of constructor in com.zone.firstaccount.controller.FileContentController required a bean of type 'com.zone.firstaccount.repository.PromoContentStore' that could not be found.

To Reproduce Steps to reproduce the behavior:

  1. Add fs starter, add spring-content-azure-storage, add needed bom dependency
<dependency>
           <groupId>com.github.paulcwarren</groupId>
           <artifactId>spring-content-fs-boot-starter</artifactId>
           <version>3.0.9</version>
       </dependency>
       <dependency>
           <groupId>com.github.paulcwarren</groupId>
           <artifactId>spring-content-azure-storage</artifactId>
           <version>3.0.9</version>
       </dependency>
       <dependency>
           <groupId>com.github.paulcwarren</groupId>
           <artifactId>spring-content-bom</artifactId>
           <version>3.0.9</version>
       </dependency>
  1. Add config
@Configuration
@EnableAzureStorage
public  class ApplicationConfigAzure {

        @Value("#{environment.AZURE_STORAGE_ENDPOINT}")
        private String endpoint;

        @Value("#{environment.AZURE_STORAGE_CONNECTION_STRING}")
        private String connString;

        @Bean
        public BlobServiceClientBuilder storage() {
                return new BlobServiceClientBuilder()
                .endpoint(endpoint)
                .connectionString(connString);
        }
}
  1. Add Entity
@Entity
@Getter
@Setter
@NoArgsConstructor
public class Promo {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Long id;
    private String name;
    private LocalDate dob;
    private Boolean hasbankAccount;
    private Boolean hasPolicy;

    @ContentId
    private String contentId;
    @ContentLength
    private long contentLength;
    private String contentMimeType = "text/plain";
}
  1. Add Store and Entity Repo , app refuses to start without @Repository annotation
@Repository
public interface PromoContentStore extends ContentStore<Promo, String> {
}
public interface PromoRepository extends CrudRepository<Promo, Long> {
}

Expected Behavior: The application should start up without any errors, and the FileContentController should be instantiated correctly with the required PromoContentStore dependency.

Actual Behavior: The application fails to start due to the error mentioned above, indicating that the PromoContentStore bean cannot be found. Suffer the error. However fs which is setup in another config not show works just fine

uhexos avatar Apr 30 '24 18:04 uhexos

Hi @uhexos , you can take a look at this example to see how it can be set up. Run the test to see the context loads.

HTH

paulcwarren avatar May 01 '24 05:05 paulcwarren

Ping. @uhexos did that help?

paulcwarren avatar May 21 '24 04:05 paulcwarren

@paulcwarren gave it a try but clearly I'm not smart enough to figure it out. In the end I gave up and just stuck with regular file system. When that's insufficient I'll take a look at azure again. Will try to recreate and post the actual error. Thanks for the help either ways @paulcwarren

uhexos avatar May 21 '24 07:05 uhexos

Closing due to inactivity. Please re-open if you return to this and still have an issue.

paulcwarren avatar Aug 30 '24 23:08 paulcwarren