在ServerContextListener中两次调用contextInilialized

时间:2018-07-19 06:41:43

标签: java jersey servletcontextlistener servlet-listeners

我对后端结构和servlet不好。我知道contextInitialized必须被调用一次。就我而言,我不知道为什么,但是它两次响了。有人提到这可能是因为虚拟主机。我在本地使用,如果为虚拟主机配置则不使用。

我在 weblogic 服务器上使用 Jersey intellij IDEA

中的 Gradle 依赖项管理器

您可以在下面找到我的 web.xml weblogic.xml 侦听器类。

@WebListener

public class ApplicationStartUpListener implements ServletContextListener {



@Inject

ApplicationContext applicationContext;



public void contextInitialized(ServletContextEvent servletContextEvent) {

    ServletContext context = servletContextEvent.getServletContext();

    applicationContext.setServletContext(context);



    try {

        System.out.println("ServiceSettings araniyor");

        String settingsClass = context.getInitParameter("settingsClass");

        if (settingsClass == null)

            throw new ServiceException("web.xml içinde settingsClass tanımı bulunamadı.");



        Class.forName(context.getInitParameter("settingsClass")).newInstance();

        ServiceSettings serviceSettings = (ServiceSettings) Class.forName(context.getInitParameter("settingsClass")).newInstance();

        if (serviceSettings == null)

            throw new ServiceException("ServiceSettings classi bulunamadi");



        System.out.println("ServiceSettings setlendi");





        applicationContext.setServiceSettings(serviceSettings);



        serviceSettings.initializeContext(context);

    } catch (Exception e) {

        System.out.print("ServletContextListener:" + e.getMessage());

    }



}



public void contextDestroyed(ServletContextEvent servletContextEvent) {

}

}

`

     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"

     version="3.1">



<context-param>

    <param-name>datasource</param-name>

    <param-value>/WEB-INF/DataSource.properties</param-value>

</context-param>



<context-param>

    <param-name>tebcache</param-name>

    <param-value>/WEB-INF/Cache.properties</param-value>

</context-param>



<context-param>

    <param-name>tebfactory</param-name>

    <param-value>/WEB-INF/Factory.properties</param-value>

</context-param>



<welcome-file-list>

    <welcome-file>/swagger/index.html</welcome-file>

</welcome-file-list>



<context-param>

    <param-name>settingsClass</param-name>

    <param-value>com.mobile.util.ServiceSettings</param-value>

</context-param>

`

<weblogic-web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

              xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-web-app

              http://www.bea.com/ns/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd"

              xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app">



<context-root>kosova-kurumsal</context-root>



<container-descriptor>

    <show-archived-real-path-enabled>true</show-archived-real-path-enabled>



    <prefer-application-packages>

        <!-- media provider -->

        <package-name>com.fasterxml.jackson.*</package-name>

        <package-name>org.codehaus.jackson.*</package-name>

        <package-name>org.codehaus.jettison.*</package-name>



        <!-- jersey -->

        <package-name>org.glassfish.jersey.media</package-name>



    </prefer-application-packages>



</container-descriptor>



<session-descriptor>

    <timeout-secs>600</timeout-secs>

    <!--<cookie-secure>true</cookie-secure>-->

    <cookie-http-only>true</cookie-http-only>

</session-descriptor>

0 个答案:

没有答案