2013-03-12 74 views
2

如何将位于我的测试资源文件夹中的applicationcontext.xml添加到web.xml中。 我想这如何在web.xml中添加应用程序上下文

<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>/test/resources/com/reg/applicationcontext.xml</param-value> 
</context-param> 

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

我运行mvn war:war命令,我在部署阿帕奇战争文件。但它显示错误。

Mar 12, 2013 11:31:07 AM org.apache.catalina.core.StandardContext startInternal 
SEVERE: Error listenerStart 
Mar 12, 2013 11:31:07 AM org.apache.catalina.core.StandardContext startInternal 
SEVERE: Context [/myapp] startup failed due to previous errors 

任何人都可以帮我吗?谢谢

localhost。

Mar 12, 2013 11:19:57 AM org.apache.catalina.core.StandardContext listenerStart 
SEVERE: Skipped installing application listeners due to previous error(s) 
Mar 12, 2013 11:31:07 AM org.apache.catalina.core.StandardContext listenerStart 
SEVERE: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener 
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener 
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1713) 
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1558) 
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:527) 
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:509) 
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:137) 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4733) 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5291) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) 
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) 
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633) 
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:977) 
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1655) 
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) 
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source) 
    at java.util.concurrent.FutureTask.run(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    at java.lang.Thread.run(Unknown Source) 

Mar 12, 2013 11:31:07 AM org.apache.catalina.core.StandardContext listenerStart 
SEVERE: Skipped installing application listeners due to previous error(s) 
+0

你使用的是Tomcat吧?你可以发布catalina.log吗? – 2013-03-12 06:12:28

+0

请检查以下链接... http://stackoverflow.com/questions/9197112/org-apache-catalina-core-standardcontext-startinternal-severe-error-listenersta – 2013-03-12 06:16:00

+0

哪里是链接@GMR? – 2013-03-12 06:18:40

回答

2

您在类路径中缺少spring-web.jar

试着在你的Maven配置补充一点:

<dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-web</artifactId> 
    <type>jar</type> 
    <scope>compile</scope> 
</dependency> 
3

您将applicationContext.xml放在测试目录中?这是一个巨大的错误。既然你使用mvn,你应该把它放在main-> resource dir中,因为当你使用mvn war:war时,它不会收集测试目录中的文件。然后放在web.xml中

<context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value> 
      classpath:**the sub dir in you resource which the config xml is in** /applicationContext.xml 
     </param-value> 
    </context-param> 
1

这是简单的web xml文件。根据您的需要参考&更改路径。

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 

<!-- The definition of the Root Spring Container shared by all Servlets and Filters --> 
<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>/WEB-INF/spring/root-context.xml</param-value> 
</context-param> 

<!-- Creates the Spring Container shared by all Servlets and Filters --> 
<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 

<!-- Processes application requests --> 
<servlet> 
    <servlet-name>appServlet</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

<servlet-mapping> 
    <servlet-name>appServlet</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping> 

编辑: 此外,您的应用程序似乎缺少弹簧网络罐子。确保你在classpath中有它。

<dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-web</artifactId> 
    <version>${your_spring_vserion}</version> 
</dependency> 
+0

为什么有2个XML文件? – 2013-03-12 06:35:54

+0

servlet-context.xml是邮件xml文件。上面声明的可以用来声明与hibernate,spring安全相关​​的bean。有这些不同的XML文件总是更好。 – 2013-03-12 06:37:33

相关问题