Repository bean not found for service implementation
I'm new in spring boot, I came across this problem where I couldn't run the app
TLDR of the error:
I have tried debugging it, but I couldn't read and solve the problem, as I've reached with copilot to confirm whether or not I did this right, they even said my structure and annotations seem fine.
33 Replies
⌛
This post has been reserved for your question.
Hey @circle! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
ProjectServiceImpl
ProjectRepository
response from built in copilot, had to ask it
How are you running the application (which class are you running, which package is that in etc)?
Can you show your application.properties?
Here is the application.properties:
I excluded the database because I haven't used it previously, but commenting the exclusion doesn't affect anything.
I run it using
.\mvnw spring-boot:run
or with -X
It looks just fine to me, the
PortoApiApplication
is the one to runCan you show the stack trace?
Do you want me to put it in a log txt?
ideally using a codeblock?
alright, it might be if u want to debug. Coming.
I cut the spring logo part allong with some uh
It's starts around the
UnsatisfiedDependencyException
partCan you show your pom.xml?
Why do you have the
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
in your application.properties?I didn't use the database
It was raising autoconfig on datasource error
But you need the repository?
Well you can't use a repository without a valid datasource
Not yet, I haven't used it. I wanted to now
wait... let me check
well
ProjectServiceImpl
requires it
so due to the existence of ProjectServiceImpl
, you need a valid DataSource
I tried many times now, I have also made the database and table... But the error persists on that problem
I might've foudn a clue
This is the chained error, which I assume points out to the bottom of the problem
updateProjectById
is being used in a method in ProjectServiceImplWhat is
updateProjectById
supposed to be?
Why do you think Spring would allow that?That is also my question, why did I think like that. I think I misunderstood what they meant
this works...
just by commenting it
I'm thinking of a PUT method for this
that's why i abstracted the method, which I thought may be required
you can also do
void save(Project project);
I think
where the ID is in the projectYea, I saw a repo doing this implementation but I couldn't quite understand how it really works yet. I just read the docs on CrudRepository.save(), so even if it's an existing project, I may also want to use that instead?
yes
Ah, would this be the right implementation?
yeah you should be able to do something like that
and I think you might even do something like
though you'd need to test that (especially that this doesn't create a new project with a different ID)
Hard to see what it does in the background, I can't find how it works underneath, only points out to the interface when i ctrl click it.
I believe by doing that
.setId
then saving it, the .save
method saves by looking up whether it exists or not? If it does exist, then it simply overwrite the previous value with the corresponding id?I think so but you'd need to test it
it might be different if you use
@GeneratedValue
For testing it, you could
- enable logging of the SQL statements and check what is executed in the DB
- just add an existing one to the DB, change it with that approach and check which elements are in the DB afterwards💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.