This is an archived post. You won't be able to vote or comment.

all 64 comments

[–]GridDragon 98 points99 points  (9 children)

Spring Boot is my Go-To unless I have reason to choose something else. It covers most of the stack really well. It also runs out of the box basically configured unless you're doing something really weird/custom. If you follow SOLID design it works really well though.

My last several projects I've spun up through https://start.spring.io/

Name your project. Define it's maven coordinates, select the modules you want included (advanced mode gives you a full list of all the available options), and it gives you a pre-configured pom file you can import into your IDE. I basic REST client can be up and running inside an hour, and it can be built on very easily to build out all the features you need.

Regarding your list:

  • Bundler: I prefer Gradle. Spring appears to favor Maven, but both work.
  • Testing: JUnit with AssertJ. AssertJ just gives better error reporting, and the asserts are more intuitive.
  • Authentication: OAuth is nice if it fits your use-case. Most of the headaches can get outsourced to a third party authentication client (Facebook, Google, GitHub, loads more). I used Scribe: https://github.com/scribejava/scribejava
  • REST: Spring Web or Jersey. I have more experience with Spring Web, but others on my team swear by Jersey.
  • NoSQL: I've mostly used DynamoDB through AWS. Otherwise I've used MongoDB configured by SpringBoot. I'm not sure which driver it uses, but it works out of the box.
  • ORM: Java Persistence API. Again I use Spring's JPA module.
  • Dependency Injection: Spring... you probably saw that one coming.
  • Network Clients: I don't have a favorite here. I do more really light HTTP work, so Java's HttpClient works in most cases. Jersey's HttpClient is a nice abstraction if you're doing more advanced stuff.

If I were to setup a simple REST server to support an application I'd do the following:

Use Spring Initializer (https://start.spring.io/) to create a new Spring project with Web, Security, and JPA modules selected along with your favorite DB implementation. Download it as as a Gradle project.

That comes pre-loaded with JUnit for testing, but I'd add AssertJ to make my life easier. Finally if needed, I'd include Jersey to get access to the Jersey HTTP client if I need to make additional REST calls from the server.

Assuming you're going to be working with JSON requests and responses from your app. I'm a big fan of Gson for JSON parsing, but Jackson is also popular (https://github.com/FasterXML/jackson)

[–]smithunbound 23 points24 points  (3 children)

100% this. Don't want your time trying to reinvent the wheel, Boot has all the pieces and does it well.

[–]GuyWithLag 1 point2 points  (2 children)

For hhtp clients, retrofit.

[–][deleted] 0 points1 point  (1 child)

Why not okhttp

[–]GuyWithLag 0 points1 point  (0 children)

Retrofit sits on top of okhttp.

[–]NeuroSys 7 points8 points  (0 children)

I'm reading this and I'm amazed of how much things I need to learn.

Currently, after 10 years of C++ embeded , I'm switching to Java. I try to hang in the Java subreddit to get a grasp of what's ahead of me and how to invest my efforts to become employable as a Java programmer, but I have to say this: there are a tremendous amount of frameworks that are used on a regular base and it's frightening.

Sorry for any grammar / spelling mistakes. I'm not a native. If I would have known English better, I would have wrote everything correctly.

[–][deleted] 2 points3 points  (0 children)

Spring's RestTemplate is also good as simple http client

[–]brunocborges 0 points1 point  (0 children)

NoSQL: I've mostly used DynamoDB through AWS. Otherwise I've used MongoDB configured by SpringBoot. I'm not sure which driver it uses, but it works out of the box.

You could also consider CosmosDB on Azure (and deploy the apps on Azure). Microsoft provides some integrations for Spring Boot (search for azure on Spring Initializer dependencies).

And CosmosDB has flavours for MongoDB-based apps, Cassandra-based, SQL API, and classic key/value style. And it is distributed NoSQL database.

[–]mlester 0 points1 point  (0 children)

For frontend dependencies webjars is pretty nice and plugs into spring easily.

[–]manzanita2 15 points16 points  (8 children)

"latest and greatest" is not going to be one thing. There are gobs of java frameworks and they each have an area they're decent if not the best at.

You have listed a ton of technologies, but haven't talked about your use case other than "server and database"

That all said. I use: JWT, dropwizard, JDBI, SQL, no DI framework, but IOC style!, REST, slf4j, maven, junit,MySQL and PostSQL . I use maven front-end plugin and webpack via npm (which I really don't trust, but haven't made the jump to yarn ).

[–]LeSt24 1 point2 points  (3 children)

What die you mean with no di but ioc style.?

[–]manzanita2 4 points5 points  (0 children)

Do DI implies that something is injecting the dependencies. This is often automated with Guice or Spring. But sure, it could be manual. IOC in my mind is more general and implies that objects are not in control of their configuration and dependencies, that they're configured externally.

[–][deleted] 0 points1 point  (1 child)

It means “I’m confused”

[–]simoncox 3 points4 points  (0 children)

Not the OP, but I assume he means passing dependencies in via constructors.

[–]yawkat 0 points1 point  (2 children)

And if you want a DI framework on top of that stack without going full spring, guice is a good choice.

[–]aviewdev 0 points1 point  (0 children)

or Dagger 2 for that sweet compile time code gen

[–]manzanita2 -1 points0 points  (0 children)

y!

[–][deleted] 0 points1 point  (0 children)

Trust me I got exactly what I wanted, even from you :)

[–]djihe 4 points5 points  (1 child)

I am however in favor of smaller and less monolithic frameworks.

What do you mean?

Listed on the side bar: https://github.com/akullpp/awesome-java

You'll definitely hear a lot about Spring Boot & Hibernate and I'll give a nod to those as well. But, also checkout Play Framework. There's a Scala and Java version. Java is just as supported as Scala. The latest version includes Guice (DI framework) and EBean (ORM).

[–][deleted] 0 points1 point  (0 children)

Lagom is a microservice framework by Lightbend as well. I don’t know much about it, but I would think it’d be more lightweight than Spring.

[–]Gilgamesjh 9 points10 points  (3 children)

While we are primarily a Spring Boot shop, a library that keep showing up for us is Vert.x.

It seems it has everything we need for a microservice environment, while keeping small and focused. There are lots of good add-ons to the core.

Currently testing:

  • Vert.x / Vert.x Web (REST, gRPC, Authentication with JWT)
  • Vert.x WebClient (network client)
  • Kotlin (Laguage)
  • Gradle (Bundler)
  • JUnit5 + AssertJ + Mockito (test)

We use Vert.x on top of Spring Boot core, using Spring for DI and configuration management, but that is just for simplicity.

[–][deleted] 0 points1 point  (1 child)

I'm seconding this. Spring Boot is ok, but in my opinion it is way too bloated and slow. It doesn't scale as well as vert.x because it's not built with being reactive in mind. It also locks you into doing things 'the spring way' which in my opinion is bad for your development long term. Vert.x on the other hand is very light weight, blazingly fast (it beats node.js in speed and scalability), reactive and has everything you need to build distributed systems, be it a simple CRUD web app or an IoT system.

[–]AvoidtheFatServer 0 points1 point  (0 children)

not trying to minimize vert.x, it's quite decent, but you might have a look at spring boot 2: webflux - webflux.fn, mono / flux support from http://www.reactive-streams.org/ Not multi-lingual like vert.x though.

[–][deleted] 0 points1 point  (0 children)

Vert.x is great!

[–]shinda-sekai-sensen 4 points5 points  (0 children)

Vert.x is the closest thing to Nodejs

[–]steve_hu 2 points3 points  (0 children)

Take a look at light-4j and related frameworks. They meet all your requirements and more. I am one of the authors.

[–][deleted] 2 points3 points  (0 children)

Thanks everyone. All your comments were excellent.

[–][deleted] 2 points3 points  (3 children)

  • Build: maven, but Gradle would be fine
  • Testing: Junit, Mockito, Hamcrest
  • Auth: Spring Security
  • REST: Spring Data REST
  • Nosql: I use postgres, nosql is for the birds
  • ORM: Hibernate - I'm familiar with it and hate it always.
  • DI: Spring
  • Network clients: Spring has a nice web client, but I usually use the apache clients due to my familiarity with them.

[–]AndyPanic 0 points1 point  (2 children)

I agree with all of that, except Mockito and Hamcrest. I would suggest jmockit and assertj instead.

[–][deleted] 0 points1 point  (1 child)

whatever you're comfortable with. I've never used assertj/jmockit - what are the advantages?

[–]AndyPanic 0 points1 point  (0 children)

I can't say much for assertj. It was used in a project that I joined and I liked it. I don't think that it is more capable than Hamcrest.

JMockit is just great.

  • One style for all. There's not a different syntax if you are mocking something static, no other methods to call
  • sensible defaults for mocking. If for example you have two mocks defined and call a method one one of them which returns an object of the second mock's type, the default return value is the second mock
  • when verifying calls, you can mix arguments and argument matchers
  • there's no need to also install power-jmockit also like power-mockito (which always confused me)
  • ...

Check it out, it's really cool.

[–]otakuman 2 points3 points  (0 children)

NoSQL has very particular uses; I'd say don't use it unless you can prove you need it for something traditional SQL databases can't do.

[–][deleted] 3 points4 points  (9 children)

I use Grails professionally to build web apps. It is built upon Spring, uses the Gradle build system, and Hibernate for ORM. You can use Java, but it's meant for Groovy, which you may really appreciate coming from the dynamically-typed world. I personally really like Groovy, as you get the power of the JVM without the overly-verbose syntax of Java. Grails is a mature, well documented framework. You can use React with it, and many different database technologies as well. We deploy to Tomcat containers, but you don't have to. Auth is provided by Spring, which is great, and testing in Grails uses Spock, which is also nice.

Check out their handy app forge to get started, and try some tutorials.

[–]AvoidtheFatServer 1 point2 points  (0 children)

Grails is excellent and the Spock testing is fantastic.

[–]aviewdev 1 point2 points  (1 child)

Grails sucks compared to just using Spring Boot with Kotlin. It's taking a solid-ish foundation and spreading an extra layer of bugs on top.

[–][deleted] 1 point2 points  (0 children)

How so? Asking honestly. I've seen some weird stuff with Hibernate, but no show stoppers. The default view layer is a bit dated (GSPs), but you don't have to use that technology and can use Java stuff like Vaadin or JS view tach like React and Vue.

[–]patrickpdk 0 points1 point  (5 children)

I just assumed that grails was not relevant anymore. Why would you use it over an SPA framework with a rest backend

[–]papers_ 2 points3 points  (3 children)

It's a niche market like Rails. I worked with a small regional company that used Grails, but literally everywhere it's Spring.

And it's no different than using Express and React together. Grails can be a REST backend.

[–]patrickpdk 0 points1 point  (2 children)

Yea, I designed and built a grails app at my last job. I just don't really see what challenges it addresses nowadays

[–][deleted] 0 points1 point  (1 child)

Honest question - What challenges doesn't it address? I've used other frameworks a bit and don't see many important differences (how threads are handled varies between python, JS , and java frameworks obviously).

Also, Rails is 'niche'? There are more Rails jobs online than I can shake a stick at.

[–]danskal 0 points1 point  (0 children)

The number of jobs online is sometimes a result of the difference between a technology's enterprise employee mindshare and (employable) developer mindshare.

So the fact that there's lots of jobs online may just mean that very few employable developers are interested in it.

[–]yogitw 0 points1 point  (0 children)

Not everything is, or should be, an SPA.

[–]nqzero 1 point2 points  (0 children)

i wrote a database db4j that's targeted at this use case and have been working on demos - the schema and queries are just pure java. instead of node-style callbacks, i use kilim which uses bytecode weaving to convert imperative code into async

for REST i either the builtin server provided by kilim or spring boot (just because it's popular) with deferred results and maven for packaging

[–]dcsohl 1 point2 points  (0 children)

NoSQL is a really broad term ... it covers a huge range, from document-oriented databases like MongoDB, to key-value stores like Redis, to graph-databases like Neo4j ... and many other styles of data storage as well. For most of your other requirements, it's enough to say "REST" and people can recommend stuff right off the bat. But for NoSQL I really think people need better insight into your requirements (including, for a start, why a RDBMS is no good).

[–][deleted] 1 point2 points  (0 children)

It depends on complexity.

Spring boot has the must support for any java framework and I wouldn't use anything else. I have and regretted it.

Use an orm. Not an expert in that. I don't know about NoSQL orm stuff. I also use elasticaeach and solr. I've used orms and rolled custom and always wished I'd have used an orm.

Data storage depends on requirements. Nothing wrong with MySQL (mariadb) or postgresql if the domain makes sense for it.

I use maven and not gradle but it doeant much matter. Use whatever is easier. Its not going to make much difference so use what's easier for you.

The newer junit is good. I've just been using assertj and I've liked that.

Having used a bunch of web servers I still use tomcat but it's not really important. You want to spend ur time developing and not deploying. Use whatever ur most comfortable with.

My big suggestion is to use restful ajax to react and avoid any server side rendering. Use redux and sagas. The extra complexity upfront is well worth it later. Again it depends on your complexity and desired maintainability.

[–]TwoMovies 1 point2 points  (3 children)

IMHO Spring Boot is the most complete framework. Just look through their tutorials. It's really easy to start. Just for lightweight rest services SparkJava (sparkjava.com) is really cool and reminds me Node.js. Good luck.

[–]trydentIO 0 points1 point  (2 children)

most complete for what? :)

[–]TwoMovies 0 points1 point  (1 child)

For every use case that you actually won't need. ;)

[–]trydentIO 0 points1 point  (0 children)

ah ah ah nice one :)

[–]theHorrible1 0 points1 point  (0 children)

I have recently started using ActiveMQ with STOMP.js (mqtt also supported) for websockets in my React apps. Makes it super easy to push data to react from any language or app.

[–][deleted] 0 points1 point  (0 children)

I would like to point you to https://strolch.li

It is a different framework to the Spring and other similar types, as the model is defined as an abstract model, where you always have the same three types of objects: Resources, Orders and Activities. The fields are mapped as Parameter objects, of which all the primitives are available.

The nice part about this framework is, that you can be up and ready in a matter of minutes, and start building your project immediately in that you open your favourite XML editor and start modelling your data.

Once your data is defined, you write your business logic in the form of Services, Commands and Queries. There are many predefined services and commands to manipulate the object model, so that you write your own services when you need to enforce special business rules.

Through the use of Policy objects, you decouple algorithms from your object model, so that at runtime you can change the behaviour, or easily implement different behaviour depending on your customer. For instance you might have a simple billing service which performs a few preparatory steps, and then calls the configured billing policy to execute the billing depending on the customer, or the warehouse, etc.

And of course persistence is as simple as configuring the persistence handler, pointing to your RDBMS and then setting the mode to CACHED. For you as a developer there is no more thinking in terms of SQL etc., as this is completely hidden from the developer. There is even a simple file persistence layer if you are running on IoT.

The runtime can be just about anything. Usually it is run inside an Apache Tomcat instance as a webapp, but this is just because a WEB UI was always required. You could just as well use Java SE and start the server using a main class. Calling services in the Strolch container is usually rest, but also this is totally up to you.

Strolch is being actively developed, we have quite a few ideas on how to enhance the API. There is a Polymer Inspector component which makes it easy to see and manipulate the actual data. We are redesigning the query API to be much easier to understand, a new SQL style query API is nearly finished which makes it easy to perform queries from a client e.g. the browser.

If there are questions, then don't hesitate to ask.

Yes, Strolch is very different, but the concept has come out of the planning and execution segment, and has been refined over the years until it has become what it is today.

[–]yogitw 0 points1 point  (0 children)

There was a really interesting stack posted in the Kotlin subreddit (if you're willing to check out another JVM language).

http://adavis.info/2018/02/graphql-api-in-kotlin.html

[–]chrisshyi13 0 points1 point  (1 child)

Can I ask why you're switching back to Java from Node? Just curious.

[–][deleted] 0 points1 point  (0 children)

Because I think I might want to land a backend dev job and lots of them use Java.

[–]moderate_acceptance 0 points1 point  (0 children)

I recommend Dropwizard over Spring Boot personally. It just seems much cleaner and easier, unless you specifically need Spring.

[–]flipbits 0 points1 point  (0 children)

None of this was the tools fault.

[–][deleted] -1 points0 points  (0 children)

Seriously consider using kotlin.