无法初始化上下文,因为已存在根应用程序上下文

时间:2011-12-13 15:58:06

标签: hibernate spring maven jetty tapestry

我的项目使用tapestry 5.3.0,spring 3.0.6.RELEASE,hibernate 3.6.8.FINAL和maven.When 我使用mvn jetty启动jetty启动项目:运行,我得到以下内容:

2011-12-13 16:15:42.947:WARN::failed app: java.lang.RuntimeException: Exception     constructing service 'ApplicationContext': Cannot initialize context because there is  already a root application context present - check whether you have multiple ContextLoader*  definitions in your web.xml!
2011-12-13 16:15:42.948:WARN::Failed startup of context  org.mortbay.jetty.plugin.Jetty6PluginWebAppContext@98062f{/projektni,/home/borislav/eclipse_ workspace/web_apps/projektni/src/main/webapp}
java.lang.RuntimeException: Exception constructing service 'ApplicationContext': Cannot  initialize context because there is already a root application context present - check  whether you have multiple ContextLoader* definitions in your web.xml!
at  org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.obtainObjectFromCreator(J ustInTimeObjectCreator.java:78)
at   org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.createObject(JustInTimeOb jectCreator.java:56)
at $ConfigurableWebApplicationContext_10f23e440970.delegate(Unknown Source)
at $ConfigurableWebApplicationContext_10f23e440970.getBeanDefinitionCount(Unknown  Source)
at  org.apache.tapestry5.spring.SpringModule$1.initializeApplication(SpringModule.java:58)
at $ApplicationInitializer_10f23e440987.initializeApplication(Unknown Source)
at  org.apache.tapestry5.services.TapestryModule$39.initializeApplication(TapestryModule.java:25 55)
at $ApplicationInitializer_10f23e440987.initializeApplication(Unknown Source)
at $ApplicationInitializer_10f23e440983.initializeApplication(Unknown Source)
at  org.apache.tapestry5.services.TapestryModule$ServletApplicationInitializerTerminator.initial izeApplication(TapestryModule.java:411)
at $ServletApplicationInitializer_10f23e440969.initializeApplication(Unknown Source)
at org.apache.tapestry5.TapestryFilter.init(TapestryFilter.java:102)
at org.mortbay.jetty.servlet.FilterHolder.doStart(FilterHolder.java:97)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:713)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1282)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:518)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:499)
at  org.mortbay.jetty.plugin.Jetty6PluginWebAppContext.doStart(Jetty6PluginWebAppContext.java:11 5)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
at  org.mortbay.jetty.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:156 )
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.Server.doStart(Server.java:224)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.plugin.Jetty6PluginServer.start(Jetty6PluginServer.java:132)
at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:454)
at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:396)
at org.mortbay.jetty.plugin.AbstractJettyRunMojo.execute(AbstractJettyRunMojo.java:210)
at org.mortbay.jetty.plugin.Jetty6RunMojo.execute(Jetty6RunMojo.java:184)
at    org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java :107)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at  org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuild er.java:84)
at  org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuild er.java:59)
at  org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.ja va:183)
at  org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:534)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
2011-12-13 16:15:43.009:INFO::Started SelectChannelConnector@0.0.0.0:8080[INFO] 
Started Jetty Server

Web.xml看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>projektni Tapestry 5 Application</display-name>

<context-param>
    <!-- The only significant configuration for Tapestry 5, this informs Tapestry 
        of where to look for pages, components and mixins. -->
    <param-name>tapestry.app-package</param-name>
    <param-value>org.prikic.projektni</param-value>
</context-param>
<!-- Specify some additional Modules for two different execution modes: 
    development and qa. Remember that the default execution mode is production -->
<context-param>
    <param-name>tapestry.development-modules</param-name>
    <param-value>
        org.prikic.projektni.services.DevelopmentModule
    </param-value>
</context-param>
<context-param>
    <param-name>tapestry.qa-modules</param-name>
    <param-value>
        org.prikic.projektni.services.QaModule
    </param-value>
</context-param>


<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>

        <!-- /WEB-INF/application_context_dao.xml -->
        <!--  /WEB-INF/application_context*.xml -->
        classpath:application_context*.xml

    </param-value>
</context-param>

<filter>
    <filter-name>app</filter-name>
    <!-- Special filter that adds in a T5 IoC module derived from the Spring 
        WebApplicationContext. -->
    <filter-class>org.apache.tapestry5.spring.TapestrySpringFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>app</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>


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

<!-- <servlet>
    <servlet-name>context</servlet-name>
    <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>  -->

<welcome-file-list>
    <welcome-file>Index</welcome-file>
</welcome-file-list>

如果您需要其他任何源代码文件,请告诉我,我会发布它们

想法,任何人?

1 个答案:

答案 0 :(得分:7)

您应该从web.xml中删除ContextLoaderListener。以下内容来自Tapestry Spring integration页。

请省略有关创建ContextLoaderListener的部分:现在由Tapestry自动完成。