繁体   English   中英

Servlet没有默认的构造函数。

[英]Servlet does not have a default constructor.

我有这个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);
        }
    }

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

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM