I am working on JAX-RS web services but constantly getting an NPE for spring as it is not able to Autowire the class.
This is how I have defined it in the applicationContext:
<context:annotation-config />
<!-- Scan for all of Spring components such as Spring Service -->
<context:component-scan base-package="com.geidea.spring.service"></context:component-scan>
<context:component-scan base-package="com.geidea.web.rest"></context:component-scan>
<bean id="terminalDao" class="com.geidea.spring.dao.TerminalDaoImpl" />
<bean id="terminalServices" class="com.geidea.spring.service.TerminalServiceImpl" />
This is my rest Service:
package com.geidea.web.rest;
@Component
@Path(value = "/")
public class TerminalRestController{
private final Logger log = LoggerFactory.getLogger(TerminalRestController.class);
@Autowired
private TerminalService terminalService;
public TerminalService getTerminalService() {
return terminalService;
}
public void setTerminalService(TerminalService terminalService) {
this.terminalService = terminalService;
}
@POST
@Path("/processTerminals")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public ResultMessage processTerminals(TerminalsData data){
log.debug("Processing Terminals Web Service");
System.out.println(data.getTerminalsData().getCurrencyCode().getCurrencyCode()+ " "+data.getTerminalsData().getCurrencyCode().getAlphaCode());
ResultMessage response = new ResultMessage();
response.setMessage("Some Error Occurred");
response.setResponseCode("-1");
List<Term> existingTerminals = new ArrayList<Term>();
existingTerminals = terminalService.fetchTerminals();
I am getting error on this line "existingTerminals = terminalService.fetchTerminals();"
The error is:
11:47:19,721 DEBUG [rest.TerminalRestController -64] Processing Terminals Web Service
13-Jan-2020 11:47:19.725 SEVERE [http-nio-8080-exec-1] com.sun.jersey.spi.container.ContainerResponse.mapMappableContainerException The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
java.lang.NullPointerException
at com.geidea.web.rest.TerminalRestController.processTerminals(TerminalRestController.java:71)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
Thanks in advance.