15

IntelliJ IDEA を使用して Spring Mvc アプリケーションを作成した後、デフォルトの application-config ファイルを別のディレクトリに移動して名前を変更しました。今、私はこのエラーを受け取っています:「このファイルに対してアプリケーションコンテキストが構成されていません」ファイルの新しい場所は src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml です

ファイルは次のとおりです。

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

何か案は?ありがとうございました。

4

4 に答える 4

0

コードからアプリケーション コンテキストを構成した (Spring 3.1 の新機能) ので、IntelliJ のアイデアは文句を言い続けると思います。これがコードです。

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("/");

    }
}
于 2013-04-28T16:53:37.377 に答える
0

これを追加するとうまくいきました!! thx から satur6ay

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        classpath:applicationContext.xml
    </param-value>
</context-param>
于 2021-01-14T13:17:55.403 に答える