Skip to content
Advertisement

How to wire classes and objects in SpringBoot

Have SpringBoot Java app with different classes. I am not able to inject the dependencies and initialize/access the object of one class into another . Have seen the spring doc and used the annotations (@component,@Autowired etc. ), still there is an issue.

following are the classes.

Main Class ()

JavaScript

Controller class

JavaScript

RequestToken Class

JavaScript

now eventhough , I have all annotation in place , not getting why the getToken() method is not accessible in controller class using rt object. please suggest

Advertisement

Answer

Okay, let’s go in order.

First of all, all the annotations @Service, @Controller and @Repository are specifications from @Component, so you don’t need to specify @Component and @Controller in your HighChartsController.

Actually, if you check what the annotation @Controller definition is, you’ll find this:

JavaScript

Secondly, I don’t really know what do you mean with that you aren’t able to access the getToken() method, but as you wrote it seems you tried to access to that method as an static method.

You’re injecting the object, so you use the methods of the objects like in plain Java: rt.getToken(). The only difference is that the RequestToken object will be already initialized at the moment you call it.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement