I was going through this tutorial https://www.baeldung.com/spring-graphql in order to configure graphql and map objects directly to POJO, however with the new packages from https://github.com/graphql-java/graphql-java-spring the interfaces used in the tutorial don't seem to be there anymore.
Is it possible to use the same techniques (maybe using an additional package) to map grapqhl request to objects and configure datafetchers in an easier fashion than manually ?
Note that I would like this to be webflux compatible not webmvc.
The Spring Starter that Baeldung tutorial is using is coming from graphql-java-kickstart, and it is not the same as the official graphql-java Spring Starter.
Their programming models are different. The Kickstart one relies on graphql-java-tools, while the other one uses graphql-java directly. So you can just keep using the latest version of the Kickstart Spring Starter. Not sure whether it works with WebFlux, but I'd expect so.
There's also my project, GraphQL SPQR Spring Starter and a sample app here. The latest version (0.0.4) works with WebFlux, but for queries and mutations only, subscription support is coming.
Related
I have to work on an application that old interns started. The backend is made with spring-boot and using Kotlin, which I'm very new to both. The backed is a RESTful API and I need to implement an authentication and authorizations to limit the access to specific users the CRUD methods.
There's basically two user roles I need to create, an admin and a moderator one that can have access to less methods.
Does anyone have a guide on to how to make it possible?
I've found this tutorial which seems like to do what I'm looking for but it's in java and I'm not able to code everything back into Kotlin.
Also, add access restriction on a websocket as well?
There is official guide for configuring security on Kotlin:
https://spring.io/blog/2020/03/04/spring-tips-kotlin-and-spring-security
Security for websockets has two parts for configuring:
for controllers
for message brokers
There is guide for that https://www.baeldung.com/spring-security-websockets on Java, but following the example in security configuration on Kotlin you will be able to convert Java to Kotlin, anyway you can always convert Java classes in Kotlin classes in your Intellij Idea as on image:
So I have to build an offline project using MongoDB (with morphia), Java and React/Angular. I'm planning to work with react but all the solutions point to me using Spring Boot or Spring Data for this purpose. Is there no other framework that I could use to make this?
Its a very simple application where we need to list out some database entries and allow a user to make a request and change the entry values based on it.
I know Struts is also an option but remember that Im not actually going to deploy this online. This is like a show and tell to these lecturers on my own device.
NOTE I would have used Spring Data but as far as I know it doesnt have proper support for morphia? I could be wrong. Please let me know if it does
There are literally dozens of Java [micro]frameworks to chose from:
Vert.x
Javalin
Spark
Micronaut
Ratpack
Dropwizard
Ninja
Rapidoid
... and many more.
You can also try Play or Ktor or Grails. Or do some hardcore with Netty or Undertow.
Not to mention plain old servlets...
Vert.x in particular supports reactive MongoDB drivers: https://vertx.io/docs/vertx-mongo-client/java.
In PHP & Symfony world there is a tool called Sonata Admin https://sonata-project.org/ based on AdminLTE template, that is all-in-one admin tool with login, menu configuration, and what is most important - database tables HTML grid CRUD generators.
The tool saves you tons of efforts by avoiding you writing boilerplate code, moreover, there might be a scenario that you would write zero code.
We need the same but for Java and Spring stack. Any recommendations?
Take a look at JHipster project https://www.jhipster.tech/
With it you can create Spring Boot+Angular/React/Vue based applications. It provides some cool tools for generating CRUD entities by scaffolding.
https://www.javatpoint.com/spring-mvc-crud-example contains an example of how to create a Spring MVC CRUD there are plenty more examples of various spring project (This particular falls under Spring MVC).
This is not a ready-made CRUD, but a way how you could quickly implement one.
https://spring.io/guides/gs/crud-with-vaadin/ is also worth checking.
Although there are few project like spring batch admin (For batch administration), or Spring boot admin (Monitoring spring boot applications), which provides a UI, mainly spring project provides a simple programmatically way of plugging in what's needed.
It's a plug & play kind of framework which targets various aspects of an enterprise application. Chances of finding a ready-made UI app would be more on GitHub rather than a specific spring plugin.
Simple answer to your question is No spring does not provide any tool for that but spring gives you the functionalities that can reduce your work but not with zero coding.
example:
Using Spring Data JPA there is an Interface name curdRepository which
takes care of the curd Operations we dont need to implement the methods
for Curd Spring takes care of Curd operation.
Spring Security Provides the login configuration with the login form and logout mechanism.
You can use spring boot or just visit the https://start.spring.io/ it will initialize the spring project with the dependencies you need
I want to build a server for my android application.
My application lets users register and allows each user to request a list of all users registered to my application, so my server will be mainly in charge of receiving data from a user, updating the database, and sending data back to user on request.
Since I've never built a server I looked into what would be the ideal way to achieve my goals and after some reading I've found that Spring would be the right way to go, But I also found that there are all kinds of springs.
Eventually I've narrowed my options down to Spring MVC and spring Boot,
I've read that spring boot is a good start but I also read that spring boot does all the configurations for you and I want to really know how stuff works so I fear that spring boot will do all the work for me , So I thought of maybe using spring MVC but I couldn't completely figure out if Spring MVC would be good to achieve my goals or if it's mainly used for building web pages
So what would be the best suitable spring to use ?
I would prefer Spring boot. It's not just about it doing all the configuration for you. It's about Spring saving you from writing a lot of boilerplate code (you still have to do a fair bit of configuration though). Plus, it will be easy to spin up the app and test it locally (you can even test it with local file based h2 database, meaning you don't need to install any database into your machine).
Adding Spring Data JPA dependency with Spring boot will take care of persistent layer as well. And if you want to write jsp or html pages then I would recommend having a look at this thymeleaf example.
Here's the sample CRUD application I have developed with Spring boot and here's my own blog about it.
Spring MVC stands for model,view,controller. View, in general is something which is returned after your business logic has been executed and mainly suggests webpages. Spring Boot would be the easiest way to set up your server for the application. However, if you want to know how things work you can go with the basic spring. Spring, too provided classes like JdbcTemplate to reduce your boilerplate code, however it forces you to configure things yourself.
You do not have the comfort of annotating a resource and watching as the magic happens. If you want to speed up setting up a server and make things less complex go for Spring Boot.
We are planning to make a new application with spring 4.0.6 version. We use controller that can return "XML" or "JSON".
In the previous project we have successfully implemented Jersey with Spring for REST support using JAX-RS API, but after reading a few articles and suggestions from seniors they said spring is providing pretty good REST support.
Some of the points that really confused me if I use Spring REST support without using JAX-RS and Jersey are:
How marshaling and unmarshaling done in Spring MVC ?
Is it necessary for marshaling or unmarshaling need to use jax-rs.
If marshaling and unmarshaling are automatically handled by spring then how does it know about xmlRootElements.
I am still confused if Spring proving very good support of REST then why do people still go with Jersey for REST?
Really looking to know more in details.
If I said anything wrong please ignore it.
Explanation with example is really helpful.
I'd say both Jersey and Spring MVC are great - each project has its own style and strengths. Anyway, Stack Overflow is not the right place for asking subjective comparisons (your question would be closed quite quickly). If you're already using Spring for everything else and are not required to use JAX-RS, then Spring MVC makes total sense.
Regarding features like (un)marshalling, JAX-RS is just a spec after all - other libraries can offer similar features without implementing the same API.
Instead of MessageBodyReaders/Writers, Spring MVC is using HttpMessageConverters to handle (un)marshalling REST resources. Spring MVC handles content negotiation and chooses the best available converter for the job (you can annotate methods to hint at what media type they produce/consume).
No, it's not necessary to use JAX-RS to (un)marshall resources. In fact, JAX-RS implementations and Spring MVC use third party serialization libraries to do the job; so it's not tied to a particular standard.
In its 4.0.6 version, Spring supports many HttpMessageConverters, with Jackson for JSON, JAXB for XML and many others. Spring 4.1.0 added more HttpMessageConverters:
Jackson is now available for both JSON and XML
Google Protobuf
Gson for JSON, as an alternative to Jackson
To answer your last point, #XmlRootElement is a JAXB annotation and is not part of JAX-RS. Spring supports JAXB.
For a more complete example with REST in Spring, check out this getting started guide (you'll get a complete example running in 10-15 minutes).
Again the last part of your question is quite subjective - there are many popular solutions for building REST services in the JVM, not just Jersey and Spring (Dropwizard, Play! Framework, etc).
AFAIK Spring REST support is based on Spring MVC and its not JAX-RS implementation while Jersey has implemented JAX-RS specification.
Those having Spring (Core, AOP or MVC) in their project chooses Spring ReST support over JAX-RS implementor.
I recommend Jersey as its mature, implements JAX-RS and is easy to use.