Spring's @Autowired value is null. My application is deployed on weblogic 12c.
I have pasted relevant files below along with explanations.
I tried changing to @Component
DriverServlet.java: Set in web.xml. Called by weblogic. Initializes application context.
package com.clarksburg.services.configuration;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
public class DriverServlet extends HttpServlet {
public void init() throws ServletException {
// Call the AppConfig class to scan all packages
AbstractApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
System.out.println("Driver Servlet initialized;");
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
public void destroy() {
// do nothing.
}
}
AppConfig.java: Does component scanning.
package com.clarksburg.services.configuration;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan(basePackages = { "com.clarksburg.services" })
public class AppConfig {
private static final Logger logger = LogManager.getLogger(AppConfig.class.getName());
public AppConfig() {
logger.debug("App Config called by driver");
// TODO Auto-generated constructor stub
}
// Put Other Application configuration here.
}
The class 'AsynchAQMessageSvcImpl' implements 'AsynchAQMessageSvc' which was generated using WSDL. It's wired to a OSB proxy on weblogic and get's called whenever the proxy gets a JMS message on a AQ queue. It's annotated with @Service. I tried to autowire ProcessWsPayload in it but when i use it i get a null pointer exception. Printing it's value is also null.
package com.clarksburg.services.messaging;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import com.clarksburg.services.wsimport.AsynchAQMessageRequestType;
import com.clarksburg.services.wsimport.AsynchAQMessageResponseType;
import com.clarksburg.services.wsimport.AsynchAQMessageSvc;
import com.clarksburg.services.services.ProcessWsPayload;
@Service
@WebService(name = "AsynchAQMessageSvc", targetNamespace = "http://www.clarksburg.com/AsynchAQMessageSvc")
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public class AsynchAQMessageSvcImpl implements AsynchAQMessageSvc {
@Autowired
ProcessWsPayload processWsPayload;
private static final Logger logger = LogManager.getLogger(AsynchAQMessageSvcImpl.class.getName());
@Override
@WebMethod(operationName = "GetAsynchAQMessage", action = "http://www.clarksburg.com/AsynchAQMessageSvc")
@WebResult(name = "AsynchAQResponse", targetNamespace = "http://www.clarksburg.com/AsynchAQMessageSvc", partName = "response")
public AsynchAQMessageResponseType getAsynchAQMessage(
@WebParam(name = "AsynchAQRequest", targetNamespace = "http://www.clarksburg.com/AsynchAQMessageSvc", partName = "request")
AsynchAQMessageRequestType request) {
logger.debug("processWsPayload is " +processWsPayload);
processWsPayload.processWsPayload(request);
// new ProcessWsPayload().processWsPayload(request);
AsynchAQMessageResponseType response = new AsynchAQMessageResponseType();
response.setServiceResponse("Success");
return response;
}
}
ProcessWsPayload.java: It's called (successfully) by 'AsynchAQMessageSvcImpl'. It's annotated as @Component.
package com.clarksburg.services.services;
import java.math.BigInteger;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.clarksburg.services.configuration.JDBCConfig;
@Component
public class ProcessWsPayload {
private static final Logger logger = LogManager.getLogger(ProcessWsPayload.class.getName());
@Autowired
JDBCConfig jdbcConfig;
/*
* This method is called by a JMS listener. It is being invoked successfully.
* However the value of 'jdbcConfig' is null
*/
public void processWsPayload(wsPayload request) {
BigInteger wsAuditId = request.getAuditId();
system.out.println("The value of JDBCConfig is " +jdbcConfig);
try {
String SQL = "UPDATE AUDIT_TBL SET ws_descriptions = ? WHERE ws_audit_id = ?";
JDBCConfig.jdbcTemplate().update(SQL, "Success with soap send", wsAuditId);
} catch (Exception e) {
logger.debug("Failed to update table with success");
logger.error(e);
}
}
I turned on Spring's TRACE logs and have pasted lines pertaining to Autowiring below.
Spring's relevant autowired logs during deployment:-
InjectionMetadata - Registered injected element on class [com.multiplan.services.messaging.AsynchAQMessageSvcImpl]: AutowiredFieldElement for com.multiplan.services.services.ProcessWsPayload com.multiplan.services.messaging.AsynchAQMessageSvcImpl.processWsPayload
InjectionMetadata - Processing injected element of bean 'AsynchAQMessageSvcImpl': AutowiredFieldElement for com.multiplan.services.services.ProcessWsPayload com.multiplan.services.messaging.AsynchAQMessageSvcImpl.processWsPayload
InjectionMetadata - Registered injected element on class [com.multiplan.services.services.ProcessWsPayload]: AutowiredFieldElement for com.multiplan.services.configuration.JDBCConfig com.multiplan.services.services.ProcessWsPayload.jdbcConfig
InjectionMetadata - Processing injected element of bean 'processWsPayload': AutowiredFieldElement for com.multiplan.services.configuration.JDBCConfig com.multiplan.services.services.ProcessWsPayload.jdbcConfig
AutowiredAnnotationBeanPostProcessor - Autowiring by type from bean name 'processWsPayload' to bean named 'JDBCConfig'
AutowiredAnnotationBeanPostProcessor - Autowiring by type from bean name 'AsynchAQMessageSvcImpl' to bean named 'processWsPayload'