Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 初始化上下文时,不会调用ServletContextListener.contextInitialized_Java_Jsp_Servlets_Jetty_Embedded Jetty - Fatal编程技术网

Java 初始化上下文时,不会调用ServletContextListener.contextInitialized

Java 初始化上下文时,不会调用ServletContextListener.contextInitialized,java,jsp,servlets,jetty,embedded-jetty,Java,Jsp,Servlets,Jetty,Embedded Jetty,我正在创建一个war文件(progressReporter.war),并将其部署在Jetty7.2.2.v20101205上。我在contextInitialized上有一个sysout方法,我应该在jetty启动时看到它。我正在使用 java-jarstart.jar Java版本是1.6 当我在tomcat上运行时也是一样,它运行得非常好。对于jetty,我已经包括了 jetty-client-7.2.2.v20101205.jar jetty-continuation-7.2.2.v20

我正在创建一个war文件(progressReporter.war),并将其部署在Jetty7.2.2.v20101205上。我在contextInitialized上有一个sysout方法,我应该在jetty启动时看到它。我正在使用
java-jarstart.jar

Java版本是1.6

当我在tomcat上运行时也是一样,它运行得非常好。对于jetty,我已经包括了

  • jetty-client-7.2.2.v20101205.jar
  • jetty-continuation-7.2.2.v20101205.jar
  • jetty-http-7.2.2.v20101205.jar
  • jetty-io-7.2.2.v20101205.jar
  • jetty-servlets-7.2.2.v20101205.jar
  • jetty-util-7.2.2.v20101205.jar
以下是我的简历

@Override  
public void contextInitialized(ServletContextEvent servletContextEvent) {  
    ApplicationContext applicationContext = new ClassPathXmlApplicationContext(new String[] {"spring-http-config.xml", "test-spring-http-config.xml", "spring-ibatis.xml" });  
    System.out.println("setting attribute now ............... " + servletContextEvent.getServletContext());  
}  
以下是我在web.xml中的内容

<listener>  
    <listener-class>org.springframework.web.context.ContextLoaderListener  
    </listener-class>  
    <listener-class>com.client.BatchProgressorContextListener  
   </listener-class>  
</listener>
你能帮我解释一下我做错了什么,以及在码头上运行需要做些什么吗? 如果您还需要任何其他详细信息,请务必告诉我

提前感谢。

几件事:

  • 我在日志中看到上下文正在上升:
-从类路径资源加载XMLBean定义 [spring-http-config.xml]203[main] 信息 org.springframework.beans.factory.xml.XmlBeanDefinitionReader -从类路径资源加载XMLBean定义 [testspring http confi g.xml]218 [主要]信息 org.springframework.beans.factory.xml.XmlBeanDefinitionReader -从类路径资源加载XMLBean定义 [spring ibatis.xml]

所以你的代码是有效的

  • 写入控制台而不是写入日志文件。也许这就是你看不到它的原因。尝试使用commons日志记录您的消息

  • 为什么web.xml中同时包含ContextLoaderListener和BatchProgressorContextListener?(我假设BatchProgressorContextListener就是您在文章开头给出代码的那个,对吗?) 可能您只需要一个上下文侦听器来加载您的上下文,而ContextLoaderListener就足够了。 从web.xml中删除BatchProgressorContextListener并添加


上下文配置位置
类路径:spring-http-config.xml
类路径:test-spring-http-config.xml
类路径:spring-ibatis.xml
几件事:

  • 我在日志中看到上下文正在上升:
-从类路径资源加载XMLBean定义 [spring-http-config.xml]203[main] 信息 org.springframework.beans.factory.xml.XmlBeanDefinitionReader -从类路径资源加载XMLBean定义 [testspring http confi g.xml]218 [主要]信息 org.springframework.beans.factory.xml.XmlBeanDefinitionReader -从类路径资源加载XMLBean定义 [spring ibatis.xml]

所以你的代码是有效的

  • 写入控制台而不是写入日志文件。也许这就是你看不到它的原因。尝试使用commons日志记录您的消息

  • 为什么web.xml中同时包含ContextLoaderListener和BatchProgressorContextListener?(我假设BatchProgressorContextListener就是您在文章开头给出代码的那个,对吗?) 可能您只需要一个上下文侦听器来加载您的上下文,而ContextLoaderListener就足够了。 从web.xml中删除BatchProgressorContextListener并添加


上下文配置位置
类路径:spring-http-config.xml
类路径:test-spring-http-config.xml
类路径:spring-ibatis.xml

谢谢Tarlog。我有上下文参数。问题是,在单侦听器标记中,我定义了两个侦听器。现在我像这样分离了listener>listener类>org.springframework.web.context.ContextLoaderListener/listener类>/listener>listener类>com.client.BatchProgressorContextListener/listener类/listener>现在它的工作非常好。谢谢Stackoverflow谢谢Tarlog。我有上下文参数。问题是,在单侦听器标记中,我定义了两个侦听器。现在我像这样分离了listener>listener类>org.springframework.web.context.ContextLoaderListener/listener类>/listener>listener类>com.client.BatchProgressorContextListener/listener类/listener>现在它的工作非常好。谢谢你。
C:\bkup\trialLearning\jetty>java -jar start.jar
2011-01-01 20:04:10.510:INFO::jetty-7.2.2.v20101205
2011-01-01 20:04:10.525:INFO::Deployment monitor C:\bkup\trialLearning\jetty\web
apps at interval 1
2011-01-01 20:04:10.525:INFO::Deployable added: C:\bkup\trialLearning\jetty\weba
pps\progressReporter.war
2011-01-01 20:04:10.666:INFO::Copying WEB-INF/lib jar:file:/C:/bkup/trialLearnin
g/jetty/webapps/progressReporter.war!/WEB-INF/lib/ to C:\Documents and Settings\
i143628\Local Settings\Temp\jetty-0.0.0.0-8080-progressReporter.war-_progressRep
orter-any-\webinf\WEB-INF\lib
2011-01-01 20:04:12.213:INFO:progressReporter:Initializing Spring root WebApplic
ationContext
0    [main] INFO  org.springframework.web.context.ContextLoader  - Root WebAppli
cationContext: initialization started
31   [main] INFO  org.springframework.web.context.support.XmlWebApplicationConte
xt  - Refreshing Root WebApplicationContext: startup date [Sat Jan 01 20:04:12 I
ST 2011]; root of context hierarchy
93   [main] INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader
 - Loading XML bean definitions from class path resource [spring-http-config.xml
]
203  [main] INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader
 - Loading XML bean definitions from class path resource [test-spring-http-confi
g.xml]
218  [main] INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader
 - Loading XML bean definitions from class path resource [spring-ibatis.xml]
390  [main] INFO  org.springframework.beans.factory.config.PropertyPlaceholderCo
nfigurer  - Loading properties file from class path resource [qpr-config.propert
ies]
406  [main] INFO  org.springframework.beans.factory.support.DefaultListableBeanF
actory  - Pre-instantiating singletons in org.springframework.beans.factory.supp
ort.DefaultListableBeanFactory@e66f56: defining beans [org.springframework.conte
xt.annotation.internalConfigurationAnnotationProcessor,org.springframework.conte
xt.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.a
nnotation.internalRequiredAnnotationProcessor,org.springframework.context.annota
tion.internalCommonAnnotationProcessor,batchProgressUpdater,batchProgressMetrics
,progressReporterResultsQueue,cbbEventProcessorThread,timerEventProcessorThread,
eventThreadManager,eventListener,metricsAggregator,southbeachDummyClient,cbbPric
er,dummyCbb,processorThread,counterGenerater,imntInfoDao,imntStatsInfoDao,org.sp
ringframework.beans.factory.config.PropertyPlaceholderConfigurer#0,dataSource,sq
lMapClient]; root of factory hierarchy
593  [main] INFO  org.springframework.web.context.ContextLoader  - Root WebAppli
cationContext: initialization completed in 593 ms
2011-01-01 20:04:12.947:INFO::Deployment monitor C:\bkup\trialLearning\jetty\con
texts at interval 1
2011-01-01 20:04:12.947:INFO::Deployable added: C:\bkup\trialLearning\jetty\cont
exts\test.xml
2011-01-01 20:04:12.978:INFO::Extract jar:file:/C:/bkup/trialLearning/jetty/weba
pps/test.war!/ to C:\Documents and Settings\i143628\Local Settings\Temp\jetty-0.
0.0.0-8080-test.war-_-any-\webapp
2011-01-01 20:04:13.572:INFO:org.eclipse.jetty.servlets.TransparentProxy:Transpa
rentProxy @ /javadoc to http://download.eclipse.org/jetty/stable-7/apidocs
2011-01-01 20:04:13.572:INFO::Deployable added: C:\bkup\trialLearning\jetty\cont
exts\javadoc.xml
2011-01-01 20:04:13.588:INFO::Started SelectChannelConnector@0.0.0.0:8080
2011-01-01 20:12:59.369:INFO::Graceful shutdown SelectChannelConnector@0.0.0.0:8
080
2011-01-01 20:12:59.447:INFO::Graceful shutdown o.e.j.w.WebAppContext{/progressR
eporter,[file:/C:/Documents%20and%20Settings/i143628/Local%20Settings/Temp/jetty
-0.0.0.0-8080-progressReporter.war-_progressReporter-any-/webinf/, jar:file:/C:/
bkup/trialLearning/jetty/webapps/progressReporter.war!/]},C:\bkup\trialLearning\
jetty\webapps\progressReporter.war
2011-01-01 20:12:59.447:INFO::Graceful shutdown o.e.j.w.WebAppContext{/,file:/C:
/Documents%20and%20Settings/i143628/Local%20Settings/Temp/jetty-0.0.0.0-8080-tes
t.war-_-any-/webapp/},C:\bkup\trialLearning\jetty/webapps/test.war
2011-01-01 20:12:59.478:INFO::Graceful shutdown o.e.j.s.h.ContextHandler{/javado
c,file:/C:/bkup/trialLearning/jetty/javadoc}
2011-01-01 20:13:00.666:INFO:progressReporter:Closing Spring root WebApplication
Context
528453 [Thread-1] INFO  org.springframework.web.context.support.XmlWebApplicatio
nContext  - Closing Root WebApplicationContext: startup date [Sat Jan 01 20:04:1
2 IST 2011]; root of context hierarchy
528453 [Thread-1] INFO  org.springframework.beans.factory.support.DefaultListabl
eBeanFactory  - Destroying singletons in org.springframework.beans.factory.suppo
rt.DefaultListableBeanFactory@e66f56: defining beans [org.springframework.contex
t.annotation.internalConfigurationAnnotationProcessor,org.springframework.contex
t.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.an
notation.internalRequiredAnnotationProcessor,org.springframework.context.annotat
ion.internalCommonAnnotationProcessor,batchProgressUpdater,batchProgressMetrics,
progressReporterResultsQueue,cbbEventProcessorThread,timerEventProcessorThread,e
ventThreadManager,eventListener,metricsAggregator,southbeachDummyClient,cbbPrice
r,dummyCbb,processorThread,counterGenerater,imntInfoDao,imntStatsInfoDao,org.spr
ingframework.beans.factory.config.PropertyPlaceholderConfigurer#0,dataSource,sql
MapClient]; root of factory hierarchy
3   [main] INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader
 <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value> 
       classpath:spring-http-config.xml
       classpath:test-spring-http-config.xml
       classpath:spring-ibatis.xml
    </param-value>
</context-param>