SpringDataRESTwithSpringMVC:将RepositoryRestMVC配置添加到现有DispatcherServlet
我有一个现有的SpringMVC应用程序,带有DispatcherServlet和基于XML的配置 现在我想集成SpringDataREST,但我不知道如何以干净的方式实现这一点。我补充说SpringDataRESTwithSpringMVC:将RepositoryRestMVC配置添加到现有DispatcherServlet,spring,spring-mvc,web.xml,spring-data-rest,Spring,Spring Mvc,Web.xml,Spring Data Rest,我有一个现有的SpringMVC应用程序,带有DispatcherServlet和基于XML的配置 现在我想集成SpringDataREST,但我不知道如何以干净的方式实现这一点。我补充说 <context:component-scan>...</context:component-scan> 和 <bean class="com.mypackage.rest.RestConfiguration" /> 这种方法也不起作用 我还在web.xml中尝试了
<context:component-scan>...</context:component-scan>
和
<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>
myservlet
org.springframework.web.servlet.DispatcherServlet
上下文类
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
上下文配置位置
com.mypackage.rest.rest配置
1.
奇怪的是,调用了一个用@PostConstruct注释的方法,但没有调用configure*方法
在for Spring Data REST中,有一章解释了如何在代码中将Spring Data REST添加到Spring MVC应用程序中。它还说
如果您仍在Servlet2.5环境中,则标准web.xml中的上述等效项也将与此配置相同
您是如何做到这一点的?幸运的是,在这篇文章中有解释。如果能在第2.5节中引用第11.2节:-/
在Java中,这看起来像:
在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>
import org.springframework.context.annotation.Import;
import org.springframework.data.rest.webmvc.RepositoryRestMvcConfiguration;
@Configuration
@Import(RepositoryRestMvConfiguration.class)
public class MyApplicationConfiguration {
…
}
<bean class="org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration"/>