【发布时间】:2015-04-14 15:09:36
【问题描述】:
我有一个现有的带有 DispatcherServlet 和基于 XML 的配置的 Spring MVC 应用程序。
现在我想集成 Spring Data REST,但我不知道如何以干净的方式做到这一点。我加了
<context:component-scan>...</context:component-scan>
所以找到了我的 RestController,但我未能添加 RepositoryRestMvcConfiguration 配置。我尝试了不起作用的注释驱动方法
@Configuration
public class RestConfiguration extends RepositoryRestMvcConfiguration {
...
}
和
<bean class="com.mypackage.rest.RestConfiguration" />
方法也不起作用。
我还尝试了 web.xml 中的以下内容
<servlet>
<servlet-name>myservlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</init-param>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.mypackage.rest.RestConfiguration</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
奇怪的是,一个用@PostConstruct注解的方法被调用了,但不是configure*方法。
在 docs for Spring Data REST 中有一章解释了如何在代码中将 Spring Data REST 添加到 Spring MVC 应用程序中。它还说
如果您仍处于 servlet 2.5 环境中,则标准 web.xml 中的上述等效项也将与此配置相同。
你是怎么做到的?
【问题讨论】:
标签: spring spring-mvc web.xml spring-data-rest