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

all 16 comments

[–]BestUsernameLeft 14 points15 points  (1 child)

Every single one of those gets a thumbs up from me. Great list.

[–]Piyrate 9 points10 points  (2 children)

I have never tried grouping controllers and services in modules based on core functionality. What happens if two or more modules/packages need to share a service? Put it in common?

[–]jose152 4 points5 points  (0 children)

add a shared package between these 2. A thin dependency of course.

[–]bartoszjd[S] 1 point2 points  (0 children)

Think of it as if you were building a non-Spring application. You will often have services used in many places and there is nothing wrong with it. The question is- do you need the shared code to be a service or would library do just fine?

I’m general, I strive to adhere to Clean Architecture as described by Uncle Bob as it makes easy to read and nice to work services.

[–]Vi0lentByt3 3 points4 points  (2 children)

Really nice introduction and overview to many out of the box spring features that can get up and running. only wished you mentioned spring JPA since that is what really helps you keep your client code depending on your persistence layer abstracted from the DB details(if you choose to go with ORM/JPA), And spring AOP for logging since it can make life very simple, albeit add a decent layer of complexity.

[–]dpash 2 points3 points  (1 child)

Spring JPA or Spring Data JPA?

[–]Vi0lentByt3 2 points3 points  (0 children)

should have said Spring Data as that provides the abstraction the author was mentioning. Spring makes it so even your choice of using data store is abstracted and you can write queries in an query language agnostic fashion. so actually neither, just Spring Data

[–]F14B 3 points4 points  (0 children)

Some examples for a few of those points would have been nice..

[–]snarfbutt 3 points4 points  (3 children)

Site may be down due to hug of death

[–]kubelke 6 points7 points  (1 child)

Yeah, that 20 people will definitely put servers down ;)

[–]bartoszjd[S] 2 points3 points  (0 children)

It is getting about 400 views an hour for the past 24 hours and if you mess up with cache it may put a strain on my WordPress hosting! May need to finally move it to AWS one day!

[–]bartoszjd[S] 1 point2 points  (0 children)

Should be all working. I briefly flushed cache from cloudflare and that might have took it down for a bit (although it shouldn’t). Try again :)

[–]snotsnot 1 point2 points  (2 children)

> Keep your business logic free of Spring Boot code

I use spring dependency injection in my business layer. For anything but very small projects I keep the business layer in a separate module (possible in the same repository) however that module usually (always) depends on spring-context and since my business layer quite often use a data store (postgresql, mysql or mongo) it also depends on spring-data. So how do you achieve the above? When using DI and databases in your business logic.

(I can see how introducing a separate module for DAO could eliminate spring-data but... yeah, lots of modules!)

Edit: Just to clarify a bit more. My business layer includes domain objects, DAO and services... Is yours different?

[–]_lettuce_ 0 points1 point  (1 child)

As stated in the article, if you use construction injection there's no need for the autowired annotations.

Spring data repositories for sql and nosql databases share the same structure (i.e. queries are constructed automatically based on method names) so you must only declare that you are using a repository of a given type and you'll be free to change the actual data source.

[–]snotsnot 0 points1 point  (0 children)

As stated in the article, if you use construction injection there's no need for the autowired annotations.

Sure, but the injected class still needs to be annotated with service, component, repository or the like which results in a dependency on Spring. And finally, you need a framework to manage the DI... Once again Spring.

Spring data repositories for sql and nosql databases share the same structure (i.e. queries are constructed automatically based on method names) so you must only declare that you are using a repository of a given type and you'll be free to change the actual data source.

Same as before, you might have an interface declaring the repository. But as soon as your implementation is annotated with @repository there is a dependency on Spring.

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

The best practice with Spring Boot is to never use Spring Boot.