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

发布于 2024-10-10 02:43:47 字数 7085 浏览 10 评论 0原文

我正在创建一个 war 文件(progressReporter.war),并将其部署在 Jetty7.2.2.v20101205 上。我有一个关于 contextInitialized 方法的 sysout ,当码头启动时我应该看到它。我正在使用码头
java -jar start.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>

你能帮我看看这里出了什么问题吗?

以下是我启动 jetty 时的输出:

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 [email protected]:8080
2011-01-01 20:12:59.369:INFO::Graceful shutdown [email protected]: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

您能帮我看看我做错了什么以及需要做什么才能在 Jetty 上运行吗? 如果您还需要任何其他详细信息,请告诉我。

提前致谢。

I am creating a war file (progressReporter.war) and i am deploying it on Jetty7.2.2.v20101205. I have a sysout on contextInitialized method which i should see when jetty starts up. I am starting jetty using
java -jar start.jar

Java version is 1.6

Same thing when i am running on tomcat, its running absolutely fine. For jetty i have included

  • 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

Following is what i have in

@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());  
}  

Following is what i have in web.xml

<listener>  
    <listener-class>org.springframework.web.context.ContextLoaderListener  
    </listener-class>  
    <listener-class>com.client.BatchProgressorContextListener  
   </listener-class>  
</listener>

Can you please help me what's going wrong here?

Following is the output when i start jetty:

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 [email protected]:8080
2011-01-01 20:12:59.369:INFO::Graceful shutdown [email protected]: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

Can you please help me as to what i am doing wrong and what needs to be done to run on Jetty please?
Please do let me know if you need any other details as well.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

⒈起吃苦の倖褔 2024-10-17 02:43:47

几件事:

  • 我在日志中看到上下文正在上升:
3 [main] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader

- 从类路径资源加载 XML bean 定义
[spring-http-config.xml] 203 [主要]
信息
org.springframework.beans.factory.xml.XmlBeanDefinitionReader
- 从类路径资源加载 XML bean 定义
[测试-spring-http-config.xml] 218
[主要] 信息
org.springframework.beans.factory.xml.XmlBeanDefinitionReader
- 从类路径资源加载 XML bean 定义
[spring-ibatis.xml]

所以你的代码正在工作。

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

  • 为什么 web.xml 中同时存在 ContextLoaderListener 和 BatchProgressorContextListener? (我假设 BatchProgressorContextListener 是您在帖子开头给出的代码,对吧?)
    也许您只需要一个上下文侦听器来加载您的上下文,并且 ContextLoaderListener 就足够了。
    从 web.xml 中删除 BatchProgressorContextListener 并添加

 <上下文参数>
    <参数名称>contextConfigLocation
    <参数值> 
       类路径:spring-http-config.xml
       类路径:test-spring-http-config.xml
       类路径:spring-ibatis.xml
    

Few things:

  • I see in log that context is going up:
3   [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]

So your code is working.

  • You write to console instead of writing to log file. Probably this is the reason why you don't see it. Try to use commons-logging to log your message.

  • Why you have both ContextLoaderListener and BatchProgressorContextListener in web.xml? (I assume that BatchProgressorContextListener is the one with code you gave in the beginning of post, right?)
    Probably you need only one context listener that will load your context and ContextLoaderListener will be sufficient.
    Remove BatchProgressorContextListener from web.xml and add instead

 <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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文