Spring Data Rest Configuration未按预期反映

时间:2014-05-09 14:51:04

标签: spring spring-data-rest

我刚开始使用Spring Data Rest(SDR)因此没有太多经验。我最初是为Spring Data JPA工作,目前从Spring Data Neo4j开始,我必须实现SDR以生成application/hal+json响应并将存储库公开为REST服务。 我正面临一些奇怪的问题,我在Spring Doc for SDR中提到了steps以配置,但不知何故它没有按预期工作。以下是我的代码片段 存储库

public interface MyRepository extends GraphRepository<EntityBean>,NamedIndexRepository<EntityBean>, RelationshipOperationsRepository<EntityBean>
{
    @Query(value="START .... return root;")
    List<EntityBean> findByName(@Param("name")String name);

    @Query(value="START .... return root;")
    List<EntityBean> findBySurname(@Param("surname")String surname);
}  

CustomMVCConfiguration

@Configuration  
public class CustomMVCConfig extends RepositoryRestMvcConfiguration {

@Override
protected void configureRepositoryRestConfiguration(RepositoryRestConfiguration config)
{
    config.setResourceMappingForDomainType(EntityBean.class).addResourceMappingFor("surname").setPath("lastname").setPath("newPathABC");
    config.setResourceMappingForDomainType(EntityBean.class).addResourceMappingFor("name").setPath("firstName").setPath("newPathXYZ");
    config.setResourceMappingForRepository(MyRepository.class).addResourceMappingFor("findByName").setPath("MyPath").setRel("MyRel");
    config.setDefaultMediaType(MediaType.APPLICATION_JSON);
}}  

当我点击Mapped SDR servlet url时:

http://localhost:8080/app/sdrUrl/  

我得到以下输出:

{
"_links" : {
"entityBeans" : {
  "href" : "http://localhost:8080/app/sdrUrl/entityBeans{?page,size,sort}",
  "templated" : true
}
 }
}  

"_embedded" : {
"entityBeans" : [ {
  "name" : "John",
  "surname" : "Doe",
  "_links" : {
    "self" : {
      "href" : "http://localhost:8080/app/sdrUrl/entityBeans/4194"
    }
  }
}  

配置初始化肯定,(在调试时交叉检查),因为我已经为域类型和存储库类型显式设置了resourceMapping,这里发生了什么错误? 名称姓氏不会被 firstName lastName 取代 更新! 我正在使用spring-data-rest-webmvc v2.0.2.RELEASE,虽然我正在关注v1.1.x的doc,但我认为它应该按预期工作...
更新

<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
    <servlet-name>jersey-servlet</servlet-name>
    <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>com.project.resources</param-value>
    </init-param>
    <init-param>
        <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
        <param-value>true</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>jersey-servlet</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

<servlet>
    <servlet-name>SpringDataRest</servlet-name>
    <servlet-class>org.springframework.data.rest.webmvc.RepositoryRestDispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>SpringDataRest</servlet-name>
    <url-pattern>/restdb/*</url-pattern>
</servlet-mapping>
</web-app>

0 个答案:

没有答案