paulcwarren/spring-content

Something wrong with ContentStore @Autowired:(

Closed this issue · 15 comments

First of all amazing project

I am having difficulty with @Autowired on my ContentStore interface

I noticed in your example you used spring-boot-starter-parent ver.2.4.4 I am using ver.2.4.3

And the error only disappears when I block @Autowired from my @controllers

I followed this https://paulcwarren.github.io/spring-content/spring-content-fs-docs/#create-a-file-content-store

Hi @Bampho

I am sorry you are having difficulties.

I was able to use Spring Boot 2.4.3. The test are green and I was able to use the UI to upload/download some content.

So can you be more specific about the errors you are facing? Are you seeing a specific error for example? If so what is it? Can you screenshot it. Or even better upload a version of your project that demonstrate the issue.

Thanks for the response

Compilation error...
Field ContentStore in Controller required a bean of type ContentStore that could not be found.

The injection point has the following annotations:

  • @org.springbframework.beans.factory.annotation.Autowired(required=true)

Action:
Consider defining a bean of type ContentStore in your configuration

I have autowired all my repositories in my app, the error pops when I try to autowire my ContentStores.

So, the FileContentStore interface is not being found most likely. Therefore no bean is being created to satisfy the autowire in the FileContentController class.

This discovery process works the same way as Spring Data's. It performs a scan of one or more packages to find interfaces that extend ContentStore. In the case of this sample it relies on the auto-configuration provided by the spring-content-fs-boot-starter dependency to determine these packages. And auto configuration uses the package (and sub-packages) of the class annotated with the @SpringBootApplication annotation.

So I wonder did you restructure the project, or change any dependencies (other that the Spring Boot version) or anything like that?

If it is easier you can commit you project to your personal github org and point me at it. That way I can run it up and see the issue for myself.

Definitely

ContentStore from content.commons.repository still refusing
But FilesystemContentStore from content.fs.store works fine that's surprising😵

Not sure if using everything alongside Apache commons has some effects! Since I added spring content on my old project and I am impressed, the other I'll remove later.

Thanks once again🥁

Now Q: could it be possible to set storage system like e.g whatsapp/images & whatsapp/videos & whatsapp/audio using spring content?

With apache, appending the path has been doing it for me

Note:
I managed to store files on a different location using spring content, now I want to group everything, also inside those folders would be sub "entity" folders

Hi @Bampho ,

I would expect both ContentStore and FileContentStore to work.

To that end I tried modifying the Controller for gettingstarted-spring-content-fs so that it was auto-wiring the ContentStore and it worked. In fact it is a reasonably common thing to do to autowire the ContentStore, rather than your application's actual interface. When you have configured multiple stores (using different storage) for your application you have to do it this way. I am curious why it is not working so if you can commit a reproducible case I can look into it for you.

Now Q: could it be possible to set storage system like e.g whatsapp/images & whatsapp/videos & whatsapp/audio using spring content?

Yes, you can do this. The recommended approach for this is to:

  • make sure you are capturing the mime type of your content on your entity (if using Spring Content REST it will set this on the @MimeType field before calling the setContent on the Store for example but you can do it yourself if using custom controllers)
  • create a custom Converter (second example) for your store that converts your Entity to a String. This converter is used by the filesystem store's placement service to determine where the content should be placed in storage. The implementation should inspect the mime type and return the relevant location; i.e. for an image it would return /whatsapp/images/123456 for example. Note, may need to take control of generating the actual id (or filename) for new content.

HTH

Thanks for the link

Working on #jms at the current moment, I'll circle back to images very soon.

The other day I stripped my pom with no luck on ContentStore but I'll also try to send link back in time so you can have a look.

Hi @Bampho , any update on this?

Ooh dear been working on something else but let me make time this weekend.

Hopefully let's say Friday I'll have a solid response

Using #java11, still no luck with ContentStore but fs works just fine

Problem: filesystem root gets located under AppData/Local/Temp with or without StoreConfig, I ended up, forcing that to new File(path). I was thinking the default would be /project - /static folder

But I'll circle back to the .docs Incase I missed something

Thanks

Hi @Bampho ,

Sorry I missed this comment for some reason. Yes, by default the spring boot starter for the filesystem storage module will put the content under a tmp folder. And a new one everytime you start your app. Its akin to using an "in-memory" db for example. If you want to provide a stable root for your filesystem store then you need to provide a filesystem resource loader bean and as part of that you can define "where" on the filesystem you want your docs stored. See the docs for more info.

Let me know if you still need help with the ContentStore issue. Although, I am a bit lost as to what that issue is now :-)

Ping

Hey Mr Warren

Thanks again for your response, honestly don't know how I missed that particular line in your .docs but I managed to resolve the issue

Thanks in a million 😊

Cool. No worries. This bug covers quite a lot. Are we resolved now or do you need asssistance with anything else?

I am super

Closing. Please feel free to reopen if there is anything further.