I have this Servlet which consists its constructor as well but when i am trying to run my application on Weblogic server it gives me an error that "SocialMediaSessionHandler" does not have a default constructor. That application is running well on other platform but when i switched between server's that gives me an error: Error occurred while instantiating servlet: "SocialMediaSessionHandler".
public class SocialMediaSessionHandler extends HttpServlet {
private static final long serialVersionUID = 1L;
HttpSession session = null;
private static final CDLoggerInterface log = CDLogger
.getLogger(SocialMediaSessionHandler.class);
Resource resource = new ClassPathResource("/fp.properties");
private boolean debugEnabled;
String serverUrl = "";
IWebServiceManager webServiceManager;
Utility util = null;
/**
* @see HttpServlet#HttpServlet()
*/
public SocialMediaSessionHandler() {
util = new Utility();
// TODO Auto-generated constructor stub
try {
ApplicationContext context = LoadSpringManageService
.LoadApplicationContext();
webServiceManager = (IWebServiceManager) context
.getBean("webserviceManager");
Properties props = PropertiesLoaderUtils.loadProperties(resource);
if (props.getProperty("debug.enable") != null
&& props.getProperty("debug.enable") != "")
debugEnabled = Boolean.parseBoolean(props
.getProperty("debug.enable"));
if (props.getProperty("server.url") != null
&& props.getProperty("server.url") != "")
serverUrl = props.getProperty("server.url");
} catch (MalformedURLException e) {
log.error("MalformedURLException occured.....", e);
} catch (Exception e) {
log.error("Problem in loading CD Logger properties file", e);
}
}
When we are looking at the life cycle of a Servlet, its initially loads the class and then the Servlet instance will be created by calling default constructor. and the the steps goes on.
But now in your case you are overloading the constructor, there by prohibiting the creation of default constructor by the container.Default constructor( constructor without any arguments). Default constructor is created only when no constructor is created by you.
moreover its not a good practice to define a constructor in a Servlet.
Lets do some R&D try writing a default constructor in your class and my guess is it should work.