SoFunction
Updated on 2025-03-08

Problem and solution to the Tomcat server startup error in idea

Tomcat server startup error in idea

Use the tools:

  • idea14
  • Tomcat 8.0.23

1. The project was running well before. After suddenly cloning it from GitHub, it opened it in idea. An error occurred when running Tomcat.

The source code of the error is as follows:

04-Mar-2018 00:32:05.636 SEVERE [RMI TCP Connection(3)-127.0.0.1] Context initialization failed

 : IOException parsing XML document from ServletContext resource [/WEB-INF/]; nested exception is : Could not open ServletContext resource [/WEB-INF/]

2. After many times on Baidu, I finally understood why I reported this wrong.

The reason is that the project was downloaded from github and runs for the first time on the local computer.

Read the error code:

nested exception is : Could not open ServletContext resource [/WEB-INF/]

It can be seen that its roughly means:

The file exception cannot be found and the file path cannot be opened. This file is the spring configuration file.

There are two reasons: either the file is not used, or the file path is wrong.

But I have this file, so it must be the path error.

3. Finally, I found that there is no path to configure the file in my file, so I wrote this code into it:

<!-- set upSpringThe configuration file startup path -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        classpath*:
    </param-value>
</context-param>

Notice

When putting it in, try to put this code in the front position, because the web project will initialize the context after tomcat is started.

This configuration specifies the file location of the context configuration. After the context initialization is completed, the remaining configurations should continue to be loaded.

Our springMVC servlet is only related configuration of the springMVC framework.

Just like the configuration of struts2, the overall project is still managed by spring.

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.