paulcwarren / spring-content

Cloud-Native Storage and Enterprise Content Services (ECMS) for Spring
https://paulcwarren.github.io/spring-content/
Apache License 2.0
260 stars 63 forks source link

Unable to Use Azure Data Storage in Springboot #1923

Open uhexos opened 2 months ago

uhexos commented 2 months ago

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>
  2. 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";
    }
  2. 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
paulcwarren commented 2 months ago

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 commented 1 month ago

Ping. @uhexos did that help?

uhexos commented 1 month ago

@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