-2
Problem
I am working on a Spring Boot project that depends on other project, these projects are my entities, services and the like.
I use the note Autowired
to inject my dependencies, example:
@Autowired
TermService termService;
Works perfectly on mine controller
, however the project grew and decided to create new classes in a new package.
And that’s when the problem arises, when I use the Autowired
in these new classes no dependency is injected and the object remains null.
I looked it up and all I could find was the note Component
in the classes, however it did not work.
Post more details on the structure of your project, as well as the structure of your dependency
– nullptr
It is a conventional Spring Boot design, has no special configuration.
– Wictor Chaves
Can be several things, without the structure of the project can not help
– nullptr
But what do you need? Because if you are going to post the whole structure of the project the question will become giant, as I said earlier is a conventional structure of a Spring Boot project, as it is a standard project I see no need to post this part that every Spring Boot project has.
– Wictor Chaves
All over again I asked this in question, created a package and created new classes within this package, that’s what’s new in the project.
– Wictor Chaves
Package structure, the main class annotated with
@SpringBootApplication
, the package and the class presenting injection problem (all with Imports :) )– nullptr
The class with the annotation "Springbootapplication" there are no changes, it is like in a new project, only has the "main" and inside the command "Springapplication.run(nameDaclas..."
– Wictor Chaves
Now the class is a new class too, there’s nothing in it, I just created a new class and took the code that was in the controller and put it there.
– Wictor Chaves
Let’s go continue this discussion in chat.
– nullptr
What happens is that when I put the "Autowired" in this new class the injection does not work.
– Wictor Chaves
I agree with @nullptr about posting more details. Naming and organizing project directories influence a lot of Spring projects.
– Gustavo
A print of the organization by the IDE already helps.
– Gustavo
@Gustavo changed the question and put the structure print, the folder "build" was the one I created
– Wictor Chaves
It looks OK. Somewhere in your code you use without spring injection:
new TermService()
?– Gustavo
I have to write a lot to send the answer, the answer is: No
– Wictor Chaves
Already used the Can packageScan?
– Caio Augusto Papai