Null Service Instance with @Autowired

Asked

Viewed 875 times

0

Hello, everyone. I am making a Springboot REST webservice application with JAVA. I need a method to run from time to time. For this, I am using Quartz (org.Quartz). The class method is executed in the time I want, normally. However, this method instantiates a controller to execute a search method in the database, and this search method is not working.

The instantiated controller class uses a Service interface with Annotation @Autowired. When I try to execute some method of the controller that uses this interface, it gives an error saying that it is null.

I even tried to search the bank directly for the class executed periodically, but accuses that Entitymanager is null.


Stacktrace:

2016-01-21 12:59:28.596 ERROR 11284 --- [eduler_Worker-1] org.quartz.core.JobRunShell              : Job mainGroup.mainJob threw an unhandled Exception: 

java.lang.NullPointerException: null
at    br.com.conexaonfe.canais.app.controller.ControladorController.findByAppNServer(ControladorController.java:73) ~[classes/:na]
at br.com.conexaonfe.canais.app.controller.ControladorJob.execute(ControladorJob.java:39) ~[classes/:na]
at org.quartz.core.JobRunShell.run(JobRunShell.java:202) ~[quartz-2.2.2.jar:na]
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) [quartz-2.2.2.jar:na]

2016-01-21 12:59:28.596 ERROR 11284 --- [eduler_Worker-1] org.quartz.core.ErrorLogger              : Job (mainGroup.mainJob threw an exception.

Controllersjob (class that is run periodically by Quartz: http://codepaste.net/xsxkxx

Controller (controller class I mentioned): http://codepaste.net/szag64

Controller service (Service interface used by the controller): http://codepaste.net/b59mn5

Controladorserviceimpl (implementation of the above interface): http://codepaste.net/qv1m27

Controladorrepository (repository interface): http://codepaste.net/o8oc69

Repositoryjpa controller (implementation of the above interface): http://codepaste.net/9dfhzm

Controller: http://codepaste.net/wwzmaw

Main application class (it starts Quartz): http://codepaste.net/wohb2n


Thank you in advance!


EDITED

Guys, I managed to find the solution by researching a lot. I leave here the solution: https://stackoverflow.com/questions/11965600/how-do-i-manually-autowire-a-bean-with-spring.

  • What your Spring configuration file looks like?

  • No application.properties only has database settings. Access is working perfectly, I have done many tests.

1 answer

0


I did a lot of research and I was able to find the solution and the reason for the problem.

Example of the link:

B bean = new B();
AutowireCapableBeanFactory factory = applicationContext.getAutowireCapableBeanFactory();
factory.autowireBean( bean );
factory.initializeBean( bean, "bean" );

Browser other questions tagged

You are not signed in. Login or sign up in order to post.