1
我通过@Configuration类使用Spring MVC:如何在使用java配置类时正确配置Spring MVC webapp?
@Configuration
@EnableWebMvc
public class WebConfiguration extends WebMvcConfigurerAdapter {
// more stuff
}
在我的web.xml我创建的ApplicationContext:
<context-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>my.package.WebConfiguration</param-value>
</context-param>
,我也创建一个DispatcherServlet的,如下:
<servlet>
<servlet-name>mywebapp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mywebapp</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
为了让dispatcherServlet工作,我需要一个mywebapp-servlet.xml现在,它是空的。我真的需要mywebapp-servlet.xml文件吗?
不幸的是我仍然在码头6.x,所以没有servlet 3,但我。 – 2012-02-22 01:38:04
@Jon:好的。但有这个答案解决了你的问题?请接受它或告诉我为什么不。 – sinuhepop 2012-02-22 01:46:40
@Sinuehepop:我得到'自定义WebApplicationContext类[my.package.WebConfiguration]不是类型ConfigurableWebApplicationContext' – 2012-02-22 01:54:25