Application context not configured for this file как исправить

I have created a Spring Mvc application using IntelliJ IDEA and then I moved and renamed the default application-config file to another directory.
Now I am getting this error : ‘Application context not configured for this file’
The new place of the file is src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml

The file is this one:

<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?
Thank you.

asked Apr 27, 2013 at 21:33

skiabox's user avatar

0

Check the config of spring in the web.xml file.

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

The contextConfigLocation parameter config the xml location about spring,
Check you web.xml is correct.

If you load the xml by java code,like @skiabox, you can ignore this warning.

answered Dec 12, 2017 at 3:18

Satur6ay's user avatar

Satur6aySatur6ay

1212 silver badges2 bronze badges

I’ve configured application context from code (a new feature of spring 3.1) so I believe that IntelliJ idea will keep complaining.
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("/");

    }
}

answered Apr 28, 2013 at 16:53

skiabox's user avatar

skiaboxskiabox

3,40912 gold badges63 silver badges95 bronze badges

Satur6ay’s comment helps me particularry.

But xml-file was coloured «red» by Idea.
I found thar resources folder had not «resource»-icon, but had standard gray folder icon.
So, I went to File -> Project Structure -> my module -> found there «resorces» folder -> «Mark as» -> Resources.

xml-reference in web.xml become valid and all other references in xml-spring-configs ()become green-valid

answered Nov 16, 2018 at 10:11

Андрей Костров's user avatar

Adding this worked for me!! thx to satur6ay

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

answered Jan 14, 2021 at 13:17

Dasari Swaroop Kumar's user avatar

Today when running ssm, applicationContext.xml file generated Application context not configured foe this file this warning, after Baidu solved, because the file is not configured to the project (folder copy directly from another file over)
Solution:
file-> project structure, click the plus sign, select the profile you want to add, click OK, solved.

Copyright Complaint      
Spam Report

Теги:  idea

Это означает, что вновь построенный пружинный профиль не добавляется к весне (я понимаю это).

Простые шаги, чтобы получить

Выберите редактор левый верхний угловой файл —> Структура проекта

тогда

Не забудьте подать заявку. ОК


Интеллектуальная рекомендация

Конфигурация эксперимента по расширению NGINX MONO

Каталог статьи 1 Развертывание установки Nginx (опущено) 2 Измените файл конфигурации NGINX.conf 3 Создайте связанный каталог 4 Установите статические ресурсы 5 Перезапуск Nginx. 6 брандмауэр выпускае…

Анализ скрипта Hadoop

start-all.sh libexec/hadoop-config.sh-set переменная sbin/start-dfs.sh ─config $ hadoop_conf_dir — start hdfs libexec/hdfs-config.sh sbin/hadoop-daemons.sh — Запуск сценария Guardian…

Создайте и опубликуйте свой собственный пакет npm

На основе npm на платформе nodejs мы можем загружать множество установочных пакетов npm по желанию. Как создать собственный пакет npm? Это просто, перестань говорить ерунду и начни это ~ Перед тем, ка…

Модуль Python

       Приступил к созданию проекта Python. Учитывая проблему импорта пользовательских функций между различными уровнями, Гу сослался на блоги других людей и резюмировал модули Pyt…

Вам также может понравиться

Intellij Idea Основной плагин

Intellij Idea Основной плагин Не будь собой, это абсолютно легко! Действительно Действительно .ignore Maven Helper FindBugs-IDEA Alibaba Java Coding Guidelines Lombok Mongo Plugin MyBatis Log Plugin O…

Внедрение в Android меню фильтра меню условий

В пакетном комбинированном элементе управления реализовано простое меню фильтрации нескольких условий: вы можете настроить условия фильтрации в соответствии с вашими потребностями, динамически добавля…

Check the config of spring in the web.xml file.

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

The contextConfigLocation parameter config the xml location about spring,
Check you web.xml is correct.

If you load the xml by java code,like @skiabox, you can ignore this warning.

Comments

  • I have created a Spring Mvc application using IntelliJ IDEA and then I moved and renamed the default application-config file to another directory.
    Now I am getting this error : ‘Application context not configured for this file’
    The new place of the file is src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml

    The file is this one:

    <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?
    Thank you.

Recents

score:0

I’ve configured application context from code (a new feature of spring 3.1) so I believe that IntelliJ idea will keep complaining.
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("/");

    }
}

score:0

Satur6ay’s comment helps me particularry.

But xml-file was coloured «red» by Idea.
I found thar resources folder had not «resource»-icon, but had standard gray folder icon.
So, I went to File -> Project Structure -> my module -> found there «resorces» folder -> «Mark as» -> Resources.

xml-reference in web.xml become valid and all other references in xml-spring-configs ()become green-valid

score:0

Adding this worked for me!! thx to satur6ay

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

score:1

Check the config of spring in the web.xml file.

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

The contextConfigLocation parameter config the xml location about spring,
Check you web.xml is correct.

If you load the xml by java code,like @skiabox, you can ignore this warning.

Related Query

  • ‘Application context not configured for this file’ error after moving and renaming the default application-config.xml of IntelliJ IDEA
  • PUT and POST getting 405 Method Not Allowed Error for Restful Web Services
  • Getting this org.springframework.web.servlet.DispatcherServlet noHandlerFound error and WARNING: No mapping found for HTTP request URI in Spring MVC
  • JS and CSS file not found error in spring 3.0 web mvc
  • Why is it best to NOT load up the file system of your application with content in a production scenario for spring web apps?
  • Error in unit testing in Spring MVC: context configuration file not found
  • Spring boot application is not running after getting error Caused by: java.lang.NoClassDefFoundError: org/eclipse/jetty/server/RequestLog$Writer
  • Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback
  • Error displaying jsp page and excel file ‘No mapping found for HTTP request with URI
  • How to configure log4j in a Spring Mvc application configured with Java Annotations and using a log4j.properties file
  • Error after moving <mvc:annotation-driven/>: no declaration can be found for element ‘mvc:annotation-driven’
  • context path for file upload without HttpRequest in REST application
  • tomcat 7 server will not start after deleting and reinstalling Spring PetClinic sample application
  • Why is this initialized and configured Dispatcher Servlet not processing any request?
  • Spring Application 404 for css file but not for html file
  • My Spring Application is not working. 404 error is coming instead of jsp file
  • Spring MVC- Internal Server Error + File Not Found Exception Servlet Context Resource
  • File and logger was not created for slf4j
  • spring MVC application is not working when using <context:component-scan> and throws 404 error
  • I have error after deploy WAR file to remote server(on local machine not error)
  • Not able to load image file in jsp of spring mvc and not getting alternate text for image
  • This application has no explicit mapping for /error
  • How to distinguish between null and not provided values for partial updates in Spring Rest Controller
  • Configure ViewResolver with Spring Boot and annotations gives No mapping found for HTTP request with URI error
  • What CMS to use for Spring MVC web application and device responsive web design?
  • applicationContext not finding Controllers for Servlet context
  • Spring Security logout does not work — does not clear security context and authenticated user still exists
  • Spring root application context and servlet context confusion
  • Meaning and solution for Spring 3 error message? «Using getResponseBodyAsStream instead is recommended»
  • How to Post multipart/form-data for a File Upload using SpringMVC and MockMVC

More Query from same tag

  • Why am I getting a 404 error with my Spring MVC project?
  • Twitter Bootstrap with Spring MVC
  • Aspect method interception over a Controller
  • Spring MVC: use different JSR-303 validators on the same bean?
  • Spring MVC XML output from a RestController
  • Spring 3 MVC — Does Anything Just Work? Very Simple Use Case Not Working
  • JSR 303 Validation with Spring (MVC) on WebSphere
  • Pattern for Spring-MVC stateful interaction
  • Spring configuration for spring-mongo-data service
  • Spring MVC form:errors using Ajax
  • Tomcat 7 startup issue using STS 3.0.1
  • Spring MVC — RequestMapping — Execute only if a parameter is not present
  • How to redirect page after ajax complete?
  • Spring: Creating a truly scalable Thread Pool with ThreadPoolTaskExecutor
  • Widfly logging configuration with SpringMVC application
  • cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element ‘constructor-arg’
  • Spring + Hibernate + Spring Security + REST API with Angular2 Front End Without NodeJS
  • Spring MVC using GeneratedKeyHolder() — java.io.NotSerializableException
  • Unable to locate Spring NameSpaceHandler — Spring’s mvc-basic in equinox using MANIFEST.MF similar to web-console Spring DM sample webapp
  • Migrating from jersey to spring-mvc/rest: ContainerRequestFilter, ContainerResponseFilter
  • Spring restTemplate NoClassDefFoundError
  • How I can set my Views files(.html) resource from «webapp» to «resources» folder in SpringMVC project
  • delete functionality not working properly select all checkboxes
  • Generating RESTful controllers without full scaffolding
  • how to Share model object in @RequestMapping methods in spring mvc without using session?
  • Hibernate joining two tables
  • Spring in JBoss starts 2 contexts
  • JSF(view) + Spring MVC bad choice? Even after JSF being an official EE specification, any replacements?
  • Can’t find some deprecated constant variables in spring security
  • Maven configuration for Multi Module Project

Понравилась статья? Поделить с друзьями:
  • Как исправить сведения в больничном листе
  • Как найти эквивалент металла по водороду
  • Как исправить мятый лист
  • Как найти масштаб помещения
  • Сбежала змея в квартире как найти