Error "application context is not configured for this file" after moving and renaming the standard application-config.xml IntelliJ IDEA

I created a Spring Mvc application using IntelliJ IDEA, and then moved and renamed the default application configuration file to another directory. Now I get this error: "The application context is not configured for this file" The new file location is src / main / webapp / WEB-INF / spring / appServlet / servlet-context.xml

The file is as follows:

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <!-- Enables the Spring MVC @Controller programming model --> <mvc:annotation-driven/> <mvc:resources mapping="/resources/**" location="/"/> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/pages/"/> <property name="suffix" value=".jspx"/> </bean> <context:component-scan base-package="com.apress.prospring3.ch17.web.controller"/> </beans> 

Any ideas? Thanks.

+8
source share
3 answers

I set up the application context from the code (new spring 3.1 feature), so I believe the IntelliJ idea will complain. Here is the code.

 package com.apress.prospring3.ch17.web.init; import org.springframework.web.WebApplicationInitializer; import org.springframework.web.context.support.XmlWebApplicationContext; import org.springframework.web.servlet.DispatcherServlet; import javax.servlet.MultipartConfigElement; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.ServletRegistration; public class MyWebAppInitializer implements WebApplicationInitializer{ @Override public void onStartup(ServletContext container) throws ServletException { XmlWebApplicationContext appContext = new XmlWebApplicationContext(); appContext.setConfigLocation("/WEB-INF/spring/appServlet/servlet-context.xml"); ServletRegistration.Dynamic dispatcher = container.addServlet("appServlet", new DispatcherServlet(appContext)); MultipartConfigElement multipartConfigElement = new MultipartConfigElement(null, 5000000, 5000000, 0); dispatcher.setMultipartConfig(multipartConfigElement); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/"); } } 
0
source

Check the spring configuration in the web.xml file.

 <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:applicationContext.xml </param-value> </context-param> 

The contextConfigLocation parameter sets the xml location near spring.Check if web.xml is being used correctly.

If you download xml using java code like @skiabox, you can ignore this warning.

0
source

Saturday commentary especially helps me.

But the xml file was painted with a "red" idea. I found that the resource folder does not have a -icon "resource", but it has a standard gray folder icon. So, I went to File β†’ Project Structure β†’ my module β†’ found there a folder "resorces" β†’ "Mark as" β†’ Resources.

The xml link in web.xml becomes valid, and all other links in xml-spring-configs () turn green

0
source

All Articles