I noted that the one uses the restful controller approach and the other uses the RepositoryRestResource and omits the controller. I guess I'm trying to find out which would be the better approach. To give more ideas on my API. I basically envisage it needing some authentication (likely OAuth) and authorization. eg authenticated to view x and authorized to edit x.
I'm looking for my API to then power a website and then iOS / Andoird if necessary.
On a related side note, I just wondered if there were any tools to generate JPA entity classes from an existing DB structure? I'm using intellij community
Post by:Pete Letkeman
Welcome to CodeRanch Jonathon.
I hope that you find the community here welcoming, helpful, knowledgeable and sharing.
To answer your question about some of the differences between the two tutorials:
Plus this tutorial uses the @SpringBootApplication notation
Tutorial wrote:@SpringBootApplication is a convenience annotation that adds all of the following:
@Configuration tags the class as a source of bean definitions for the application context.
@EnableAutoConfiguration tells Spring Boot to start adding beans based on classpath settings, other beans, and various property settings.
Normally you would add @EnableWebMvc for a Spring MVC app, but Spring Boot adds it automatically when it sees spring-webmvc on the classpath.
This flags the application as a web application and activates key behaviors such as setting up a DispatcherServlet.
@ComponentScan tells Spring to look for other components, configurations, and services in the hello package, allowing it to find the controllers.
Tutorial wrote:At runtime, Spring Data REST will create an implementation of this interface automatically.
Then it will use the @RepositoryRestResource annotation to direct Spring MVC to create RESTful endpoints at /people.
Spring Boot "magically" creates some of the end points that you may need when dealing with data.
However you may still need to add in some extra logic, in which case you would need to use a controller.
This tutorial https://spring.io/guides/gs/rest-service/ titled "Building a RESTful Web Service" does not access any sort of database or use Spring Data.
It simply maps a value form the URL to the output. This is why you need a controller, to handle the mapping and any other logic you may need to program.
Jonathon Roberts wrote:To give more ideas on my API. I basically envisage it needing some authentication (likely OAuth) and authorization. eg authenticated to view x and authorized to edit x.
I had briefly seen the tutorial you mentioned before, but I'll look into it in more detail.
I'm still trying to fully understand all the annotations and when/where to use them.
But you answered my question! It seems i'll need a controller to to manage the access to certain end points, just wasn't sure if I was missing pieces to Spring and going about it wrong!
Post by:Pete Letkeman
You are welcome Jonathon.
Jonathon Roberts wrote:I'm looking for my API to then power a website and then iOS / Andoird if necessary.
Here is a possible idea for this which I was able to do a couple of years ago with ASP.NET using C# and IOS programming.
1) On the server side using Java/Spring create an SQLite database.
2) Have the mobile device download and use that as the database.
3) Have the mobile device update the SQLite database locally.
4) Upload the SQLite database back to the server from the mobile device.
5) Have the server read the SQLite database and process the transactions.
I have not tried this with Android and Java/Spring, however I do have plans in implement this within the next few weeks.