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