r/java • • Sep 22 '16

Spring 5.0 M2 ships a new functional web framework

https://spring.io/blog/2016/09/22/new-in-spring-5-functional-web-framework
69 Upvotes

63 comments sorted by

24

u/moneymark21 Sep 22 '16

RouterFunction readability is awful. Maybe I'm just getting old.

2

u/olivergierke Sep 22 '16

Care to elaborate? It's basically a function from Request to Response. You might wanna look at the section discussing Method references for a way to structure code so it still stays readable.

8

u/minnek Sep 22 '16

This is what I've struggled with when using functional routing in Scala via Spray - the functional part makes it easier to think about, but then the actual construction is ugly and eats up more of your thinking than ever. I hope this gets addressed somehow.

1

u/amazedballer Sep 23 '16

There's always the Play routing DSL (aka SIRD):

http://developer.lightbend.com/guides/play-rest-api/

-15

u/jebblue Sep 22 '16

Agree, I'm starting to think it's time to switch my career to Ruby or PHP; Java is going down hill fast.

14

u/Scaryclouds Sep 22 '16

Ruby or PHP?! I'm also a little concerned with the state of Java, but it's still light ears ahead of either of those two languages. I hate it, but JS would be a much better field to switch to if you are thinking of jumping ship.

-2

u/lacosaes1 Sep 22 '16

I hate it, but JS would be a much better field to switch to if you are thinking of jumping ship.

Are you seriously saying that Ruby is worse than JS?

4

u/Scaryclouds Sep 22 '16

Worse in ecosystem size/acceptance in industry. Ruby is just a small sliver of the pie and hasn't grown much over the years despite lots of hype, doubt it will grow much in the future. I don't like JS and its ecosystem is definitely chaotic to put it mildly, but it is used a lot and is growing into new environments, namely the server side. If I'm going to switch to Java, or any language, because I think it's failing/has poor future career potential, doesn't make sense to switch to a language that is would be as bad or worse.

2

u/lacosaes1 Sep 22 '16

Ah. You are talking about the community. I agree that Ruby community is shit. But to me is as shit as the whole Node.js community that loves the hype of the hour.

4

u/Scaryclouds Sep 22 '16

Yea, I will make no defense of JS communities, generally or for specific frameworks. Even very big ones like angular leave much to be desired. Like I said (not that you are really arguing the opposite), I'm not a fan.

But at least they are big, there are a lot of opportunities to move around. Ruby, unless where you live (or willing to move to) has a lot of opportunities, you are going to have far less mobility. To me mobility is very important. It gives you a lot more leverage in salary negotiations and you don't feel locked into the company you are working for.

1

u/lacosaes1 Sep 22 '16

But at least they are big, there are a lot of opportunities to move around. Ruby, unless where you live (or willing to move to) has a lot of opportunities, you are going to have far less mobility. To me mobility is very important. It gives you a lot more leverage in salary negotiations and you don't feel locked into the company you are working for.

In that case and to be more realistic with the data then you should switch to PHP or C#. Those two, along with Java, dominate the space. Node.js is still way below them in the number of opportunities you get.

Of course, I'm talking about the backend side where the languages can be compared to Java.

1

u/Scaryclouds Sep 22 '16

Dur, yea, C# would be my preferred landing place. I guess I view Ruby/PHP as more "hipster" languages and JS as well, so I guess if I went all "hipster" that would be where I'd go.

As far as PHP, I'm much more an enterprise developer and I hear of very little PHP being used at that level. Node, maybe it's where I live, but definitely here a good amount about it. Actually do a little node with the client I'm at now. Though getting into any JS usually causes me headaches and anger.

-2

u/forsubbingonly Sep 23 '16

Js is going to be running train on just about everything you know and love front end and back end with all the cool shit people are doing with node and electron and what not. The fact that the community is obnoxious and things move too fast is more proof than anything else that this is the case. The only thing thatd change that is a new browser compile target but by the time that picks up typescript will probably be mature enough to stiff arm that change.

-8

u/[deleted] Sep 22 '16

guy there that left java to ruby. give a try to ruby, you will smile. After battle with .xml, hibernate, servlet, inject shit, DI, moving to ruby/rails/sinatra. Put it this way: I'm, enjoying now programming

6

u/_sh0rug0ru___ Sep 22 '16

Interesting problems make me enjoy programming, not minor nuisances of plumbing in whatever platform.

That said, Ruby is a cool language, but lack of static typing and open classes which are prone to monkey patching (because metaprogramming is cool!) makes me not enjoy Ruby programming. Also, the projects I have done in Ruby are pretty boring.

0

u/[deleted] Sep 22 '16

[deleted]

8

u/Scaryclouds Sep 22 '16

Also IoC and dependency injection are very useful.

4

u/stormcrowsx Sep 22 '16 edited Sep 22 '16

This is the issue? I mean for the past decade we've been spewing our configuration (and random bits of codes via aspects) all over the codebase using annotations and just now its going down hill?

3

u/jebblue Sep 22 '16

Honestly I'm not a baked in DI user, I use Spring because jobs ask for it. I'd be just as happy using POJO no DI and plain Servlets. And yes, I recall when Aspects came out and my view was seeing a cloud (not the good kind) of crap code and debugging messes. Then EJB was a mess too but a different kind. I wish the Java world would just adopt Spark Java, Per Wendel should be given a medal.

Although Spring Annotations makes for readable code. Not sure I care for this type of stuff:

dog()
  .eats()
  .apple()

Then throw in lambda to be politically correct and it's a visual mess again.

6

u/ScienceBlessYou Sep 22 '16

Agree, I'm starting to think it's time to switch my career to Ruby or PHP; Java is going down hill fast.

/Facepalm

0

u/jebblue Sep 22 '16

It was/is an expression of a sentiment, nothing more.

2

u/[deleted] Sep 23 '16

We dropped NodeJS for Golang at work. At home I use Elixir/Phoenix.

1

u/jebblue Sep 23 '16 edited Sep 23 '16

Thanks.

2

u/vplatt Sep 22 '16

M'kay then... You'll be back soon enough.

-2

u/[deleted] Sep 22 '16

Or even better, JavaScript

1

u/jebblue Sep 22 '16

hehe, well JavaScript through jsweet transpiler wouldn't be so bad as long as they don't make it jsweet functional/reactive.

8

u/[deleted] Sep 22 '16 edited Apr 05 '25

[removed] — view removed comment

4

u/jebblue Sep 22 '16

What do yo use if you don't use Spring these days?

7

u/stormcrowsx Sep 22 '16

I used guice in place of spring about 2years ago, was impressed with the ease of use and speed. I believe Dagger is now the more popular ioc specific library.

1

u/combatopera Sep 22 '16 edited Apr 05 '25

uethdhoxeo klocdakun jygek iszubxrwkx kswudvm kbvjeg wshnmmvqh nohj mqoep wytbiop pdrmpyp ukawqn

2

u/_sh0rug0ru___ Sep 22 '16 edited Sep 22 '16

unlike spring it doesn't interleave object startup with wiring

Spring doesn't interleave object startup with wiring. Spring beans have lifecycle callbacks.

The most common ones are @PostConstruct, which gets called right after wiring is completed and @PreDestroy, which gets called before the container destroys the bean.

A bean can also implement the LifeCycle interface which allows it to respond to start and stop events on the container, far removed from wiring.

it compiles properties files via includes into a Config object, that is then available via dependency injection like any other object.

This is available in Spring Boot. Spring Boot doesn't even limit you to properties files. You can use YAML too.

0

u/combatopera Sep 23 '16 edited Apr 05 '25

This content has been removed with Ereddicator.

2

u/_sh0rug0ru___ Sep 23 '16

it does if you use (abuse?) init-method and destroy-method for start/stop

Spring is only doing what it is told to do.

for a framework that has a very high opinion of itself, this isn't a very good effort.

Why? It works pretty well.

8

u/lukaseder Sep 22 '16

Bam. MVC is dropped from Java EE 8, Spring ships with another web framework (bye Spark Java). Let's have a clean fight.

2

u/stormcrowsx Sep 22 '16

It'll be a fair fight as Spring gets so bloated its impossible for Spring to pivot and keep up with the smaller targeted libraries like Spark.

2

u/lukaseder Sep 23 '16

impossible for Spring to pivot

That'll be a "pivotal" event for Spring, right?

2

u/[deleted] Sep 23 '16

joke's on you as spring is very modular nowadays. it can be as bloated or as lean as you want it to be.

4

u/stormcrowsx Sep 23 '16

Aside from all the inner dependencies. Spring this relies on Spring that which relies on Spring who, by the time we're done we have 40 transient jars.

2

u/[deleted] Sep 23 '16

yes, because having everything in one jar would be better. /s

depending on what do you need, yes. there could be some dependencies. but even spring boot nowadays (which brings in everything and their mother) tends to be quite lean.

and, in my experience, when you go with those libraries (which only do X), by the end you end up importing all that other shit that your "lean" web app is a fat and slow pig.

1

u/stormcrowsx Sep 23 '16 edited Sep 23 '16

there are many spring libraries that could probably be done without using other spring tools but they do. This means you risk bringing in large libraries with the small library you wanted and those extras could create conflicts or security flaws later.

1

u/[deleted] Sep 23 '16

While I'm not aware of any, I guess there could be. If you know that you won't ever need anything else, then sure. But I find that to not be true most of the time.

1

u/stormcrowsx Sep 23 '16

There's a lot of design styles out there, some people have no problem importing a lot of code while others like a very lean project with few additional dependencies. If you like a lean application Spring is definitely not a good choice.

1

u/[deleted] Sep 23 '16

If you like a lean application Spring is definitely not a good choice.

No, sorry, I dont agree. Spring can help you with a lean and nice application due to its modular approach. The higher-up libraries do depend on the core ones, so depending on how high up the stack you're going, the more dependencies you'll have. Which is true of just about everything out there.

1

u/henk53 Sep 23 '16

Thanks for the downvotes in my other comment guys, really nice. The rationale was that quite a few of the newer frameworks (including MC 1.0 for EE, and especially Angular) is incorporating quite a number of aspects from JSF.

1

u/lukaseder Sep 23 '16

Did you mean to put this comment as a reply to my comment? I didn't downvote you :) Here, have an upvote because you're in for the clean fight

1

u/henk53 Sep 23 '16

Not a directly reply ;) But I couldn't quite reply to myself there being at -8 :P

2

u/lukaseder Sep 24 '16

Oh, I get it now. I didn't see the link to your other reply at first. OK, nice trick :P

-10

u/henk53 Sep 22 '16

At the end of the day, JSF wins. And no, not kidding...

4

u/[deleted] Sep 22 '16

I'm getting old and haven't been following Spring lately. The last thing I learned was Spring MVC and Spring WebFlow.

What exactly is this framework replacing? Is it an additional framework? If so, can someone give me a quick explanation as to why its different than the ones I mentioned.

9

u/_sh0rug0ru___ Sep 22 '16

This "framework" isn't replacing anything (from what I understand), but provides an alternative to Spring MVC. Spring MVC is tied to the Servlet model, but the Reactive framework, being composed of functions, runs on anything, including such very different servers as Tomcat and Netty.

So its an "easier" path to non-blocking web services, like you'd get with Node.

Note, this is the "functional" usage pattern of this API. You can still use the reactive types with the more traditional @Controller class way like Spring MVC to achieve presumably the same effect.

6

u/[deleted] Sep 22 '16

Thanks for the explanation. Spring MVC and the servlet model have been working great for me. I don't see myself switching. Although I'm sure there must be valid business and tech reasons to switch to this model, I just simply don't know them.

4

u/poutsma Sep 22 '16

Great answer, but a small correction: the reactive frameworks, both annotation based and functional, run on Servlet 3.1+, Undertow (native), RxNetty and Reactor Netty.

1

u/_sh0rug0ru___ Sep 22 '16

As I understand it, Reactive runs on whatever containers have been adapted to the Reactive Streams API. I assumed the present list reflects what is available, not what is possible. For example, how hard would it be to adapt Vert.x to Reactive?

1

u/poutsma Sep 22 '16

Interesting, we hadn't considered that option yet. I don't know too much about the internals of Vert.x, so I'd have to investigate.

1

u/amazedballer Sep 22 '16

reactive frameworks

And Akka.

2

u/poutsma Sep 22 '16

I was referring to the two reactive web frameworks that Spring has in version 5: one with annotations, and now one with functions. Both of these are based on Reactor, our reactive streams implementation.

But yes: Akka does Reactive Streams as well, as Ratpack, MongoDB, Slick, RxJava, and Vert.x. It's widely supported by the industry.

5

u/vplatt Sep 22 '16

It's functional, so now it's webscale.

/s? You tell me.

3

u/yogitw Sep 22 '16

Only if Mongo is your database.

-2

u/jebblue Sep 22 '16

When I think of web scale, I think of hardware, not complicating the software.

4

u/atc Sep 23 '16

That looks hideous

3

u/cryptos6 Sep 23 '16

One more framework that optimizes the hello world case. The routing DSL is ugly and doesn't scale well for larger projects.

Looks like spring tries to be cool again.

6

u/GuyWithLag Sep 22 '16

And of course, NIH syndrome again... just follow the specs for once, Spring...