L'affichage d'un @OneToMany sous-ressources de l'association au Printemps de Données RESTE

Actuellement, j'ai un Ressort de Démarrage de l'application à l'aide de Données du Printemps de REPOS. J'ai une entité de domaine Post qui a le @OneToMany relation à une autre entité de domaine, Comment. Ces cours sont structurés comme suit:

Post.java:

@Entity
public class Post {

    @Id
    @GeneratedValue
    private long id;
    private String author;
    private String content;
    private String title;

    @OneToMany
    private List<Comment> comments;

    //Standard getters and setters...
}

Comment.java:

@Entity
public class Comment {

    @Id
    @GeneratedValue
    private long id;
    private String author;
    private String content;

    @ManyToOne
    private Post post;

    //Standard getters and setters...
}

Printemps de Données RESTE JPA dépôts sont à la base des implémentations de CrudRepository:

PostRepository.java:

public interface PostRepository extends CrudRepository<Post, Long> { }

CommentRepository.java:

public interface CommentRepository extends CrudRepository<Comment, Long> { }

L'application de point d'entrée est un standard de Printemps simple application de Démarrage. Tout est configuré stock.

Application.java

@Configuration
@EnableJpaRepositories
@Import(RepositoryRestMvcConfiguration.class)
@EnableAutoConfiguration
public class Application {

    public static void main(final String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

Tout semble fonctionner correctement. Quand je lance l'application, tout semble fonctionner correctement. Je peux POSTER un nouveau message objet http://localhost:8080/posts comme suit:

Corps:
{"author":"testAuthor", "title":"test", "content":"hello world"}

Suite à http://localhost:8080/posts/1:

{
    "author": "testAuthor",
    "content": "hello world",
    "title": "test",
    "_links": {
        "self": {
            "href": "http://localhost:8080/posts/1"
        },
        "comments": {
            "href": "http://localhost:8080/posts/1/comments"
        }
    }
}

Cependant, lorsque j'effectue une OBTENIR à http://localhost:8080/posts/1/comments - je obtenir un objet vide {} retourné, et si j'essaie de POSTER un commentaire à la même URI, j'obtiens un HTTP 405 method not Allowed.

Quelle est la bonne façon de créer un Comment des ressources et de l'associer à ce Post? J'aimerais éviter de les publier directement sur http://localhost:8080/comments si possible.

InformationsquelleAutor ccampo | 2014-08-14