TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Learning Spring with Kotlin – Sprint 0

68 点作者 joaogfarias大约 5 年前

2 条评论

jillesvangurp大约 5 年前
I&#x27;ve been using spring and Kotlin together for nearly 3 years. Since then, a lot of Kotlin specifics have crept into Spring. Also, there&#x27;s an effort to move to a fully declarative Kotlin DSL for driving spring (kofu), which gets rid of basically all anotations, AOP processing, and other magic that makes spring both nice and hard to debug. At this point, if you are using Spring and not using Kotlin: you are doing it wrong. You are missing out on a ton of stuff the Spring people did to support Kotlin. Yes Java is still supported but it is increasingly in the same way that Google hasn&#x27;t completely deprecated Java for Android yet despite that obviously very much being a second class citizen in that ecosystem.<p>In short, if you are a conservative institution like a bank and evolving your tech stack at a glacial pace; yes you can still use Java. Everybody else, you probably should be using Kotlin.<p>My advice to anyone looking to do this is:<p>1) Do it, it&#x27;s easy and you end up with better code. You can start simple and mix Java and Kotlin code. I would advice starting with some tests or some new features.<p>2) Beware of the java idioms and cruft in Spring and do things the Kotlin way. So, DSLs instead of annotations + AOP, co-routines instead of spring flux, immutable data classes instead of java beans, etc.<p>3) Spring has a lot of stuff and not all of it is great or even good. IMHO the added advantage of e.g. spring-cloud or spring-data is very limited and sometimes it&#x27;s just very limiting&#x2F;backwards. I ripped out spring-data on several projects where people naively supposed it was the easiest&#x2F;best way to interact with Elasticsearch. It turns out it is neither. Spring cloud sounds nice until you realize most of the stuff you need is supported in the amazon driver but yet not exposed in spring-cloud. Also all the code samples on Amazon are for their own driver and not for spring-cloud.<p>4) Re-assess if you actually want to go anywhere near hibernate. IMHO it made a lot of sense when java beans were hard to write. Kotlin data classes take away most of that pain and there are some nice alternatives. Also, you should be using non blocking IO for talking to your DB and hibernate is still stuck on blocking IO. That in itself is a good reason to not use it on new projects.<p>Once you get a bit further, you&#x27;ll find yourself wondering if ktor would work. The answer is probably yes. It&#x27;s actually pretty good. Spring does a lot of things but ultimately do you really need all of that and the associated complexity?
评论 #22871204 未加载
评论 #22871350 未加载
评论 #22870528 未加载
评论 #22870685 未加载
评论 #22872275 未加载
评论 #22870833 未加载
评论 #22870471 未加载
评论 #22871310 未加载
fergie大约 5 年前
Some guy writes an article where he says he is thinking about learning Spring with Kotlin and this is worthy of the front page of Hacker News??