0

我有这个 Servlet,它也包含它的构造函数,但是当我尝试在 Weblogic 服务器上运行我的应用程序时,它给了我一个错误,即“SocialMediaSessionHandler”没有默认构造函数。该应用程序在其他平台上运行良好,但是当我在服务器之间切换时出现错误:实例化 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);
        }
    }
4

1 回答 1

0

当我们查看 Servlet 的生命周期时,它最初会加载类,然后通过调用默认构造函数来创建 Servlet 实例。并且步骤继续。

但是现在在您的情况下,您正在重载构造函数,通过禁止容器创建默认构造函数。默认构造函数(没有任何参数的构造函数)。仅当您没有创建构造函数时才会创建默认构造函数。

此外,在 Servlet 中定义构造函数并不是一个好习惯。

让我们做一些研发尝试在你的类中编写一个默认构造函数,我猜它应该可以工作。

于 2014-09-16T13:30:34.753 回答