ski*_*box 9 spring spring-mvc intellij-idea
我使用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>
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?谢谢.
我已经从代码中配置了应用程序上下文(spring 3.1的一个新功能),所以我相信IntelliJ idea会继续抱怨。这是代码。
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("/");
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
22908 次 |
最近记录: |