2

How to add applicationcontext.xml which is in my test resources folder to web.xml. I tried this

<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> 

I run the mvn war:war command and I am deploying the war file in apache. But it shows error.

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

Can anyone help me? Thanks

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)
6
  • You're using tomcat right? Can you post catalina.log? Commented Mar 12, 2013 at 6:12
  • please check the below link... stackoverflow.com/questions/9197112/… Commented Mar 12, 2013 at 6:16
  • where is the link @GMR? Commented Mar 12, 2013 at 6:18
  • @IswantoSan 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 [/appanalytix] startup failed due to previous errors Commented Mar 12, 2013 at 6:20
  • @ShijuKBabu, how about localhost.log? can you post it in your question? Commented Mar 12, 2013 at 6:21

3 Answers 3

3

You put applicationContext.xml in test dir? that's a huge mistake. since you use mvn, you should put it in main->resource dir, because when you use mvn war:war, it doesn't collect the file in test dir. Then put below in 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>
Sign up to request clarification or add additional context in comments.

Comments

2

You're missing spring-web.jar in your classpath.

Try to add this in your maven configuration:

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

Comments

1

This is the simple web xml file. Refer it & change paths according to your needs.

<?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>

EDIT: Also your app seem to be missing spring-web jar. Make sure you have it in classpath.

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

1 Comment

servlet-context.xml is the mail xml file. The one declared above can be used to declare beans related to hibernate, spring security. It's always better to have have differenet xml files for these.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.