spring-content
spring-content copied to clipboard
Unable to Use Azure Data Storage in Springboot
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:
- 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>
- 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);
}
}
- 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";
}
- 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
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
Ping. @uhexos did that help?
@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
Closing due to inactivity. Please re-open if you return to this and still have an issue.