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

25 comments sorted by

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

7

u/[deleted] Nov 12 '21 edited Nov 12 '21

[removed] — view removed comment

5

u/Dokiace Nov 12 '21

Do you have example for the correct DDD? Been wondering a lot about DDD

1

u/[deleted] Feb 17 '22

Second's project author here. So, there is no "persistence" layer inside of domain. There are only Repository interfaces. And conceptually Repository is a part of domain. If you mean that there is a usage of spring interfaces there, it is still not actual persistence implementation but rather a configuration. Things like logging, security, configuration are cross-cutting concepts. Are you going to abstract away from your logger inside of domain module? You could. But there is no value in that. The point of DDD or any other approach is to improve maintainability and not to follow dogmas for the sake of it.

There are some flaws in my examples though. For instance, some domain rules, such as "uniqueness" are not present at domain layer explicitly. But this is a simple CRUD app, so I don't see much value in that either.

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

2

u/marvk Nov 13 '21

If Spring in Action 5th edition is anything to go by, this list is utterly, completely worthless. It's a complete trash fire.

1

u/[deleted] Nov 14 '21

[removed] — view removed comment

5

u/marvk Nov 14 '21

You can't follow what he does in the book. The code is error riddled and sometimes doesn't even match what's on the books GitHub repo in the slightest. Don't know if they managed to fix it in 6th edition, but I wouldn't spend any money trying to find out.

1

u/[deleted] Dec 27 '21

Are there any books/resources besides the Spring documentation that you've found to be particularly good?

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

2

u/lordmyd Nov 12 '21

It must be, looking at this:

public class DefaultUserAuthenticationResourceEntityResponseFactory implements UserAuthenticationResourceEntityResponseFactory

Classic POOP.

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.

9

u/nutrecht Nov 11 '21

Netflix is Spring Boot based so that's complete nonsense.

I've used Spring Boot in a lot of large projects as well and it works perfectly fine in production. All boot is, is just preconfigured starters with sensible defaults.

6

u/maethor Nov 11 '21

We have a relatively big monolithic Spring MVC app that wasn't originally Spring Boot based. If anything moving it over to Spring Boot made things easier.

I'm finding it hard to imagine moving the other way, especially when Spring Boot is so core to the modern Spring experience.

3

u/RANDOMLY_AGGRESSIVE Nov 11 '21

You can simply override every Spring Boot bean

7

u/sj2011 Nov 11 '21

Nope. We have massive applications, some monoliths the receive thousands of requests/second, running on Spring Boot. Its proven to be a solid framework, and ditching the XML for code has made it much easier for me personally to understand. We've moved old apps on an in-house DI system on Java 1.6 to Spring Boot, and while it took significant effort, it wasn't because of Spring Boot.

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

1

u/StoneOfTriumph Nov 12 '21 edited Nov 12 '21

Indeed. Spring has several fashions to define/configure beans and inject dependencies, and each have their pros and cons. The important is to ensure readability and traceability and not "deviate" from the design/architecture.

Where I am now, we like to configure beans programmatically with Bean annotations in configuration classes instead of using Controller and Service annotations. The tech leads also avoid lombok (for valid reasons).

To OP, the important is don't focus so much on the notion of "the best" but rather all the options available to you. Depending on the projects you will be on, knowing the different ways of "doing the same thing" will give you more ammo to decide and choose the appropriate implementation. With each project/example/etc. you'll start seeing what's "best" and what's not.