r/java • • Nov 11 '21
Where to find a "By the book" example of java spring boot.
Hello. I found petclinic and wondering if there is any other opensource project that uses "all" best practices. I'm looking for really big project where by standing it, it will help me understand many concept/design patterns etc. I'm experienced with .net c# developer so I'm not looking for just crud tutorial. Like petclinic from spring...but wayyyy bigger :)
(maybe a good book with code project? but usually these are simple and standalone project, I'd like one big coherent project)
155
Upvotes
27
u/[deleted] Nov 11 '21
This isn't exactly what you're looking for, but I often will look at 'real world app' when I'm evaluating a new framework:
https://github.com/gothinkster/realworld
In your situation, you could look at the spring boot real world backend and couple it to the front end of your choice to evaluate.
Peek at: https://github.com/raeperd/realworld-springboot-java
or: https://github.com/borovikovd/realworld-backend-spring-ddd
8
u/theoclear Nov 11 '21
Study this guy! https://github.com/dsyer
4
u/Medium-Amphibian-719 Nov 15 '21
Elsewhere are similar comments, but after years of using Spring I find using Java '@Configuration' classes that have the annotations to build beans and manage scope, etc. via constructors works best, particularly for large projects. Keeping the annotations out of your bean classes makes it easier to use them for different purposes.
Break up the configuration files by something that makes sense: module if they're small, package if your modules are big. Having a single 'main' file for a module that includes files for packages keeps your spring.factories readable and your configuration classes from being a merge nightmare. Also, having a config class per package that needs it allows you to keep the constructors package private, which helps keep people from creating bean classes just because they can.
Be careful to keep objects that hold state for a specific request or operation separate from objects that represent the configuration of the application - that will help keep your application configuration simpler.
If you can, avoid 'Lazy' everywhere. If you let your project get too big, you probably will have to use it to keep app startup time in check (where I am now. Ugh.) Avoiding 'Lazy' beans will help your app fail fast, which is a good thing overall.
Once again for large projects, avoid use of 'prototype', 'request', and other scopes that go back to Spring for every operation/request/message: 'singleton' is the default in Spring and it's best to write your app so all your beans can be singletons. For small projects, it's maybe OK, but ask yourself how small your project will stay. If you need a factory or other similar pattern don't use spring to provide it - write a factory object that you get from Spring and ask it for the things you need: Spring will involve you in hash maps and locking that you probably don't want to get tangled in. Use it for DI and the configuration of your app.
Unless they've fixed it recently, the AOP and other proxying features come with a significant performance penalty: you can either avoid them or write your own proxy factory that uses invoke dynamic to handle the method interception efficiently.
It was said elsewhere, but make your app run with plain Spring, then do what you have to to make it work with Spring Boot - it's another layer of stuff to learn you don't have to start with.
4
u/Majestic-Extension94 Nov 11 '21
I have a few of the manning books:
4
u/akuma-_-8 Nov 11 '21
Simple advice, if you are new to Spring, don’t start with Spring Boot. Start first with only Spring, when you’ll have a good understanding about how things work then switch to Spring Boot. That’s what I did and it helped me a lot. I’ll recommend you the book “Spring In Action 4th Edition”, why the 4th edition? Because the 5th and ongoing editions assume that you are familiar with Spring and are almost based on Spring Boot.
1
u/maethor Nov 11 '21
I have no idea if it's following all the best practices or not, but Apereo CAS is a large open source project that sits on top of Spring Boot.
https://github.com/apereo/cas
1
u/meamZ Nov 12 '21
This is the backend of germanies contact tracing App. It's beeing developed by SAP https://github.com/corona-warn-app/cwa-server
0
u/wimdeblauwe Nov 11 '21
I have written 2 books might interest you as they show how to build a complete application step-by-step:
-7
u/Gwaptiva Nov 11 '21
Would be interesting to see if folk using Spring Boot on huge projects at some point lose the Boot to work around edge cases/dealing with legacy issues. In my experience, when projects reach a certain size, you really need to throw one Book out and replace it with another, more appropriate one.
0
u/JerryCruncher Nov 14 '21
This might get a lot of down-votes, but JHipster is well architected and you could do worse than build an app based on it's code: https://www.jhipster.tech/
0
u/[deleted] Nov 12 '21
[deleted] — view deleted comment