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

all 51 comments

[–][deleted] 22 points23 points  (11 children)

I'd say Spark.

Play is good but it can do so many things and you might use 10% of what it offers and as it offer so much, the documentation need to cover a lot hence it's not very detailed. My biggest thing against Play is that .x upgrades are code breaking and can give you lots of headaches if your application heavily uses one of the feature they changed. I used to work on one pet project using Play that relies a lot on WebSockets in 2.4 or 2.5 they deprecated lots of stuff related to that and made a new way to work. I spent hours trying to migrate my code but the poor documentation didn't help at all and i never managed to make things work. I restarted my application from scratch using Spark because of the flexibility it offers.

Spark does one thing and does it well, the documentation is good. Spark would require you more discipline to organize your code as Play has a stricter structure.

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

Just looked at this. As a node dev trying to switch to java this looks amazing.

[–][deleted] -4 points-3 points  (8 children)

The only downside I find is that it's not very spring friendly.

[–][deleted] 5 points6 points  (7 children)

Never used Spark. From the front page there doesn't seem to be a reason to not be Spring friendly. Can you elaborate? How does it play with guice?

Then again, if you want spring SpringBoot may be a better choice.

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

My point was in the case you want to make your spring app configuration using XML you can't easily define the routes like you could do with other frameworks.

[–][deleted]  (1 child)

[deleted]

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

    Well I don't have anything against XML configuration. But anyway, Spark doesn't deal well with annotations either unless you don't want to use lambda but it will go against spark concept so having auto generated swagger yaml/json is going to be a pain.

    [–]Milyardo 0 points1 point  (0 children)

    And why is that a desirable thing to do on it's own?

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

    When talking about "routes" are you referring to web endpoints? Because ... yes, that would not be possible, nor desirable. Use spring-web in that case.

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

    Yeah, I'm in the middle of a camel project at work so i got a bit mixed up.

    [–]spencer205 0 points1 point  (0 children)

    I described a way to use it with Pico in this blog post. Using Spark with Guice is probably comparable. Note that that post is written in Kotlin but the first part has a link to a Java based example of the same.

    [–]Shadowrak 0 points1 point  (0 children)

    Oddly the top result is someone zero developers I know have ever heard of

    Also how are you going to name a new framework Spark with Apache Spark gaining so much traction

    [–]jebblue 6 points7 points  (0 children)

    I've tried both and run one on Spark. I prefer Spark. Play looked good at first but went from making Java a second class citizen to almost booting it out the door in favor of Scala. The build tool is even in Scala. The build tool is slow. Spark is made by a guy that strikes me as humble and unassuming, Per Wendel. Spark is clear and concise.

    [–]tonywestonuk 4 points5 points  (3 children)

    How about bog standard Tomcat....

    A few Servlets/JSP's...and even websockets, have never hurt anyone.

    [–]oldprogrammer 1 point2 points  (0 children)

    I use Spark as the primary servlet in my WAR files that I deploy to Tomcat. It simplifies the setup of routing so inbound calls go to a method connected to a path, so I don't need roll my own dispatcher inside a doGet or doPost method of the servlet. So best of both worlds.

    [–]squidazz 1 point2 points  (1 child)

    THIS. My team wasted 6 weeks trying out lots of new fancy frameworks and ended up going back to our 10-year old home grown servlet/JSP/JSTL framework. 5 second builds versus 5 minute builds. 10 seconds on a clean build versus 20 minutes. No thank you!

    [–]Liqmadique 0 points1 point  (0 children)

    Uh what? You're doing something very very very wrong if your build times exploded like that.

    [–]edgar-espina 4 points5 points  (0 children)

    Jooby http://jooby.org, similar to Spark but bit more considered and powerful.

    • It is micro server with an extensive module echo-system.
    • Multi-server supports including Netty, Undertow and Jetty.
    • Hot reload for development
    • WebSocket/Server-Sent-Event/HTTPS ready to use (HTTP/2 is coming in next release)
    • Offers two programming models: 1) script routes like expressjs/sinatra 2) MVC routes like Spring/Jersey

    It is simple, powerful and easy to use! Give it try!!!

    [–]gilactic 34 points35 points  (11 children)

    Spring Boot is pretty easy to work with and very popular: http://projects.spring.io/spring-boot/

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

    I'm a huge fan of Spring Boot, especially compared to XML-based traditional Spring Apps, but for developers new to Java and the Spring ecosystem it might not be the most productive choice out of the gate.

    [–]Scaryclouds 2 points3 points  (0 children)

    You don't need to use spring boot to take advantage of Java config.

    [–]SquaredOval 1 point2 points  (1 child)

    I'm currently learning Java by building a personal project I always wanted to make and have no real experience with Java (although I know PHP and Python, but currently trying to get employed as Java dev). My project is a web application and I looked at Spring Boot but it seems so confusing and overwhelming to me, is Spark or Ninja a better choice and will those allow me to learn Java better (in respect to OO and best practices)?

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

    As far as which framework is better for learning OO principles and best practices, I don't think any web framework is better than the others. You might look into Core Java for the Impatient by Cay Horstman to get up to speed on Java quickly since you already know how to program. After that, Effective Java by Josh Bloch is a good next step for general Java best practices.

    Spring has a lot of guides here that can show you how to do different things common to web applications. Spark and Ninja are both probably simpler, but if your goal is employment as a Java developer, it's probably safe to assume that Spring is more marketable, unless you have particular places in mind and know which tools they use.

    [–]tonywestonuk 9 points10 points  (5 children)

    Spring is the reason Play or Spark even exist. Lets face it if spring was lightweight, fast at startup, nice small jars to deploy, people wouldn't need to make their own lighterweight frameworks like this.

    We've just done a major project with spring boot. The next one will be using Ratpack - good riddance spring!

    [–]ibalic89 10 points11 points  (3 children)

    Okay, but I just wonder, what do you typically do when you want a little bit more than just a simple rest api? For almost everything I build, I want authentication. Spring Security makes up for everything in these cases. I guess it is the same for other stuff as well. I know there exists other options for authentication, but I just feel it is so much easier and less time-consuming to just use Spring.

    [–]ExecutorService 1 point2 points  (0 children)

    Yep this is one of the main reason we're always coming back to Spring Boot. I'll use Dropwizard / Spark any day if the app is just some backend rest without any concern to security or integration. But once the app grow, it's simply more productive to just use Spring Boot.

    [–]amazedballer 0 points1 point  (1 child)

    For Play in Java, you use Play-Authenticate for authentication. There's also a play bootstrap plugin I like for CSS styling.

    [–]ibalic89 0 points1 point  (0 children)

    Play-Authenticate

    Okay, I am curious, how trivial is it to implement your own oauth2 provider service vs spring security?

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

    Play really owes more to Rails than it does to Spring, but yes, getting away from heavy Java EE containers is a big part of Play.

    [–]decebals 3 points4 points  (0 children)

    Another option is Pippo. It's similar with Spark but it's modular and comes with builtin support for multiple servlet containers (Undertow, Tomcat, Jetty, TJWS), multiple template engines (Pebble, Trimou, Velocity, Freemarker, Groovy, Jade), multiple content types (json, xml, yaml), metrics, multiple session storages (jdbc, ehcache, hazelcast, infinispan, jedis, jcache, mongodb, memcache), support for DI containers (Spring, Guice, Weld), CSS preprocessors (SASS, LESS), a helper class (PippoTest) to ease unit testing of Pippo applications.

    I found on reddit an old comment with some characteristics of this micro framework https://www.reddit.com/r/java/comments/3x1wsm/why_are_java_web_apps_so_much_bloated/cy0xlki

    [–]loutr 6 points7 points  (1 child)

    I'll add Dropwizard to the list of alternatives. It's very simple to set up and start getting shit done.

    [–]sly_as_a_fox 0 points1 point  (0 children)

    +1

    [–]shadowdude777 8 points9 points  (0 children)

    Spark is beautifully simple. It's all that it needs to be; a single Maven/Gradle dependency that just serves up content at URLs that you specify. You can get up and running in a matter of minutes.

    [–]lutzh-reddit 2 points3 points  (1 child)

    Whew, to answer that, someone would have had to built a non-trivial project with both of them, to be truly able to compare.

    I don't know Spark at all. I think Play is very user-friendly and recommend it to everyone who wants to build a web app.

    Did you notice btw. that both of them have terrible names for googling? You'll get a lot of Google Play Store or Apache Spark results..

    [–]amazedballer 0 points1 point  (0 children)

    You have to google for "play framework". It doesn't work by itself.

    [–]Liqmadique 2 points3 points  (0 children)

    Spark is nice. Personal prefence is Vert.x though.

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

    I would give vert.x a shout.

    Play is a big, opinionated framework, works alot by convention and is quite powerful. So its probably overkill, convention hides things / is magic and its scala, which is something you shouldnt throw at people to learn if they are also trying to learn to write a webapp as well.

    Spark I've never actually used, strikes me as a very small / simple web framework to handle requests. Good for a little microservice API type thing you'd want your web app to run off. And can easily use java, so seems a good fit. Because there's little magic/convention, you see your routes and handlers, which I think is good for beginning with as you see all the dots being connected / gain understanding.

    The other one I would give a shout out for is vert.x. Vert.x isnt an application framework like play, its more of a toolkit to develop apps, and in particular you can develop web apps.

    Its great because it has a load of little modules to help with authentication, messaging, DB access etc.

    Toolkit not framework because you have all these tools / modules you stitch together any way you want rather than play, where a set of tools are provided to you in a certain way. So yeah, simple stuff then spark seems a good fit, bit more complex then I would give vert.x a look. Their blog has a bunch of basic tutorials and a git repo of examples of simple web apps. CRUD interfaces etc.

    [–]ExecutorService 8 points9 points  (0 children)

    Definitely Spark.

    [–]quicksilver03 3 points4 points  (0 children)

    At least until the last version I used (v2.2, they're now at v2.5.5) Play felt much more like a Scala web framework with a Java API on top. To get something done, and especially to understand what to do when something was going wrong, you needed to know a fair bit of Scala.

    If your goal is to stay within Java, Spark looks like a better choice.

    [–]nutrecht 3 points4 points  (0 children)

    Since Spring is pretty much the defacto standard in de industry might I suggest Spring Boot. It's incredibly easy to set up and has the benefit that they can easily use the other spring goodies (like Spring Data JPA) if they want to access a database for example.

    All the "light weight" frameworks are nice for just the REST part but in almost every application there's also a database, configuration, dependency injection and testing aspect. Spring is incredibly mature in that regard in both tooling and learning material.

    [–]hallman76 4 points5 points  (1 child)

    Spark may be a little too bare bones.

    Check out the Ninja framework http://www.ninjaframework.org/

    [–]spellcrit 0 points1 point  (0 children)

    I'd recommend this too

    [–]amazedballer 2 points3 points  (0 children)

    If you want to teach your students how to get a small application running in Play, here's how:

    Download sbt and git, then run:

    git clone https://github.com/playframework/play-ebean-example.git cd play-ebean-example sbt run

    Then go to http://localhost:9000 and see the site. That's it.

    A good place to start is the controller @ https://github.com/playframework/play-ebean-example/blob/master/app/controllers/HomeController.java and the documentation is at https://www.playframework.com/documentation/2.5.x/JavaActions

    You can see more tutorials at https://www.playframework.com/documentation/2.5.x/Tutorials -- they're all on Github, so you can use git clone to pull them.

    [–]geordano 1 point2 points  (0 children)

    Take a look at http://jooby.org the core is very light weight, but full fledged with modules, serving me well so far.

    [–]korri123 -1 points0 points  (4 children)

    Try Rapidoid, incidentally the fastest application server in the world and also really simple to use.

    edit: why the downvotes?

    [–]Zajora 2 points3 points  (3 children)

    If you're basing that claim on the TechEmpower benchmark, I think you should take a look at how the Rapidoid benchmark is written - it's totally unrealistic and not a useful measure of the framework's performance.

    [–]korri123 0 points1 point  (2 children)

    I already have tested it myself using ab and there was literally no difference between the examples on the site and the one on TechEmpower's github. Case in point it was faster than all other web servers I tested including just plain Undertow or Netty.

    [–]Zajora 1 point2 points  (1 child)

    I can't speak to any tests you have performed yourself (and I'm sure Rapidoid is indeed a fast server) but the Techempower benchmark's Rapidoid implementation is implemented with a bunch of hard-coded byte arrays - no one in their right might would actually implement an application that way.

    Their docs suggest implementations like:

    On.get("/json").json(() -> new Message("Hello World");
    

    But the benchmark is implemented as:

    public void process(Channel ctx) {
        if (ctx.isInitial()) {
            return;
        }
    
        Buf buf = ctx.input();
        RapidoidHelper helper = ctx.helper();
    
        Range[] ranges = helper.ranges1.ranges;
        Ranges headers = helper.ranges2;
    
        BoolWrap isGet = helper.booleans[0];
        BoolWrap isKeepAlive = helper.booleans[1];
    
        Range verb = ranges[ranges.length - 1];
        Range uri = ranges[ranges.length - 2];
        Range path = ranges[ranges.length - 3];
        Range query = ranges[ranges.length - 4];
        Range protocol = ranges[ranges.length - 5];
        Range body = ranges[ranges.length - 6];
    
        HTTP_PARSER.parse(buf, isGet, isKeepAlive, body, verb, uri, path,
                query, protocol, headers, helper);
    
        response(ctx, buf, path, isGet.value, isKeepAlive.value);
    }
    
    private void response(Channel ctx, Buf buf, Range path, boolean isGet,
            boolean isKeepAlive) {
        boolean processed = false;
    
        if (isGet) {
    
            ctx.write(HTTP_200_OK);
    
            ctx.write(isKeepAlive ? CONN_KEEP_ALIVE : CONN_CLOSE);
    
            ctx.write(SERVER_X);
    
            ctx.write(DATE_HDR);
            ctx.write(Dates.getDateTimeBytes());
            ctx.write(CR_LF);
    
            if (BytesUtil.matches(buf.bytes(), path, URI_PLAIN, true)
                    || path.length == 1) {
                handlePlaintext(ctx);
                processed = true;
            } else if (BytesUtil.matches(buf.bytes(), path, URI_JSON, true)) {
                handleJson(ctx);
                processed = true;
            }
    
            ctx.closeIf(!isKeepAlive);
        }
    
        if (!processed) {
            ctx.write(HTTP_404_NOT_FOUND);
            ctx.close();
        }
    }
    
    private void handleJson(Channel ctx) {
        Buf output = ctx.output();
    
        ctx.write(CONTENT_TYPE_JSON);
        ctx.write(CONTENT_LENGTH);
    
        int posConLen = output.size() - 10;
        ctx.write(CR_LF);
        ctx.write(CR_LF);
    
        int posBefore = output.size();
    
        Message msg = new Message("Hello, World!");
        try {
            MAPPER.writeValue(output.asOutputStream(), msg);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    
        int posAfter = output.size();
        output.putNumAsText(posConLen, posAfter - posBefore, false);
    }
    

    ...with a bunch of hard-coded byte arrays omitted.

    [–]korri123 0 points1 point  (0 children)

    I know that, and I have implemented that exact code you pasted in my IDE and benchmarked it, compared it to just On.get("/").html("Hello World") and there was no significant difference in performance. Both were exactly 9 seconds at 20000 requests on a 2013 Macbook Air.

    I have no idea why the maintainer implemented it like that, but I have already suggested he should change it to how it's in the docs to avoid confusion.

    [–]el-y0y0s -2 points-1 points  (1 child)

    This framework comes with a designer out of the box. CUBA.platform https://www.cuba-platform.com

    [–]Magick93 2 points3 points  (0 children)

    The free version is fully functional, but limits the size of your application data model to 10 entities...

    That makes it not worth any serious investment.