I'm trying to use Spring data rest to build up my entities. Here's my dependencies,
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-rest', version: '1.4.1.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '1.4.1.RELEASE'
compile group: 'com.h2database', name: 'h2', version: '1.4.193'
testCompile group: 'junit', name: 'junit', version: '4.11'
Here's my definition of entities,
@Entity
public class User extends BaseEntity{
private String yguid;
private String name;
private String email;
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
private List<Message> messages;
protected User(){
super();
messages = new ArrayList<>();
}
public User(String yguid, String name, String email) {
this();
this.yguid = yguid;
this.name = name;
this.email = email;
}
}
The other,
@Entity
public class Message extends BaseEntity{
private String senderId;
private String receiverId;
private String mediaId;
@ManyToOne
private User user;
protected Message(){
super();
}
public Message(String senderId, String receiverId, String mediaId) {
this();
this.senderId = senderId;
this.receiverId = receiverId;
this.mediaId = mediaId;
}
}
These are my repositories,
public interface UserRepository extends CrudRepository<User, Long> {
}
public interface MessageRepository extends CrudRepository<Message, Long>{
}
This is my entry point.
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
When I spin up the server,and go to localhost:8080/ this is all I get,
{
_links: {
profile: {
href: "http://localhost:8080/profile"
}
}
}
I'm expecting to see the entities too, as per the Spring tutorial. What am I doing wrong here?
Have you tried annotating your repositories with @RepositoryRestResource
? This should definately work.
I think nothing is wrong with your code. Have you tried
or
?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.