19
votes
Accepted
Should I validate dtos or entities?
Without knowing what you mean by DTO or Entity, I'm going to make some assumptions, and then I can answer.
DTO — An object that represents data passed to the server from the client
Entity &...
15
votes
Is it a good idea to share repositories across microservices in Spring Boot Application?
I vehemently opposed
Vehemence makes others stop listening and limits our perception, hence our capacity to find solutions too.
In my experience, we are vehement at defending or opposing ideas we don'...
11
votes
What to cover with integration tests?
Unit tests should test the behavior of your core code. They should be deterministic, parallelizable, and fast.
Integration tests should test that the rest of the system, that you had to cut out of the ...
9
votes
Accepted
Spring Boot - What is the purpose of Autowired Constructors?
You use a real constructor for the same reasons that you use public getters and setters instead of making private variables public.
Some real-life examples: cell phones are not allowed in secure, ...
8
votes
Accepted
How to compare passwords which is stored in DB in encrypted form in secure way?
Question- If are storing passwords in encrypted format in DB and in future when user login into our website how will we perform authentication?
You never, ever store passwords encrypted. Never. ...
7
votes
Accepted
Is it a good practice to Mock entity manager in spring boot unit testing
The objective of unit testing is to validate the outcome of a certain piece of code in isolation. By mocking the EntityManager, you are only validating that your implementation calls some methods, but ...
7
votes
What to cover with integration tests?
Wow, so many questions!
Let's take a step back for a moment.
Why do we write tests? Any tests, of any kind?
The team spends time writing tests in order to save time.
Suppose a bug report is filed, and ...
6
votes
How to compare passwords which is stored in DB in encrypted form in secure way?
I don't know whether the interviewer asked something wrong on purpose to see whether you would correct him or he was just simply wrong. But when you used a hash function if someone breaks into the ...
5
votes
Can DTO have helper method that operates on DTO fields?
Do not get too hung up on DTOs being "property bags." When in doubt, fall back on good ol' fashioned Object-Oriented Programming. Classes bundle data and behavior. Your DTO needs some ...
4
votes
Spring Boot - What is the purpose of Autowired Constructors?
Let me add one more reason: testeability.
When you are going to test a class, @Autowire requires spring-context to work, which should not go dependant with unit testing, so you'll need reflection for ...
4
votes
Multithreaded processing of single REST requests
we first have to get a list of all users in the group via REST call
to the low-level API and then
for each user do two additional requests
Per the comments, you should start by reaching out to the ...
4
votes
Accepted
Is there a way to avoid a lot of calls to other microservices from one single service request?
Microservice purists will tell you first that microservices should be autonomous and thus communicate (primarily) via events rather than synchronous calls. If your client infrastructure supports this, ...
3
votes
What do you think about DTOs in Spring Data JPA project?
Both your approaches raise some concerns. The main concern about the first approach is that you'll end up with a lot of duplicate methods. This isn't exactly a problem though, because both methods ...
3
votes
Accepted
A question on microservice boundaries around monitoring
I think this is unusual. If service B has failed the health check then presumably calls to service B will result in the appropriate HTTP status code (404, 500 etc), and if that's the case then service ...
3
votes
Spring Boot REST Java Microservice: Why Use Maven Submodules?
To my experience, for small apps or very small services you are right, maven modules make thing unnecessary complex in two ways: technical and cognitive.
However, modules can be of much help when:
...
3
votes
Accepted
Using Spring Boot's @ConfigurationProperties without violating Law of Demeter
Doesn't injecting @ConfigurationProperties classes violate the Law of Demeter. Specifically, doesn't it mask the real dependency (in this case an int) as described here?
Yes and yes. If OrderService ...
3
votes
Should I validate dtos or entities?
Each layer should have own validations. For example, Business Logic Layer(BLL) and Data Access Layer(DAL) should have own validations.
Beyond this, assume that you call the BLL via network. Then, you ...
3
votes
Accepted
Does it make sense to create a WAR anymore?
It depends entirely on what your Ops setup is. Many organizations have an established operations department with procedures and ways of doing things, and they have their app servers and know how to ...
3
votes
Accepted
Which design pattern to use to make a mix of in-sequence and parallel HTTP calls?
What you're maybe looking for is simply "async programming" or non-blocking programming. The default tool to use in Java for that is CompletableFuture, unless you are using a different tool ...
3
votes
In Publish-subscribe pattern can a microservice publish message for itself
We did this in one of our services. It felt cleaner because everything was going through the same interface instead of having a separate 'internal-to-the-service' interface that behaved slightly ...
3
votes
Accepted
Implementing transactional entity lockouts with Spring and JPA
Short Answer
Don't use JPA locking to implement this. It's insufficient to deliver a good experience in the style you defined. Record check-out information about the widgets instead.
Why?
Some aspects ...
3
votes
What we called this design pattern and it is same as strategy pattern?
I initially called this the Factory Method pattern but as noted by Filip, this is not correct. It's really just a method that acts as an object factory. I can see why you might think it's related to ...
3
votes
What are the advantages of externalizing application configurations?
There are many reasons to externalize configuration. Changing configs without redeploying is a good reason for sure, but consider the impact of storing config settings in a text file in version ...
3
votes
Accepted
When does a REST API stops being one in terms of state management?
The statelessness in REST means that transaction state is not maintained between requests.
for example say i have an eCommerce api where i can purchase a "basket" of items
A Stateful API ...
2
votes
Using Spring Boot's @ConfigurationProperties without violating Law of Demeter
I think this is a better explanation of the Law of Demeter.
Simply injecting the properties as follows doesn't violate that law as you are not reaching through OrderProps and don't need to know about ...
2
votes
Spring Boot REST Java Microservice: Why Use Maven Submodules?
I have worked with varying project structures like
Everything is in same maven project, single module, different packages.
Every layer even api and implementation in different maven projects, and ...
2
votes
Accepted
Pattern for for REST API who's response depends on behavior of requests to other services
There's a lot loaded in this question. But let's address the first cry for help.
Some one help me with my design paralysis!
Step 1: stop worrying about "Best practices" and "perfect"
Step 2: ...
2
votes
Accepted
To And From Date Validation in Model
The controller should always handle validation. Because its the only one capable of actually presenting the problem to the user (be that a message, some sort of highlight, etc..).
That being said, ...
2
votes
Is it okay to have one Service with two different Repositories in Spring Boot MVC?
I think the best solution depends on how the data needs to be merged/aggregated.
Assuming that you have a database that stores EntityA and another database that stores EntityB.
If the data is ...
2
votes
Accepted
Common library for classes and communication between microservices?
The reason why people tend to recommend against shared code in between microservices is that it creates organizational interdependencies in between services and teams. It is OK to use external ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
spring-boot × 89java × 37
spring × 27
microservices × 19
rest × 11
jpa × 8
architecture × 7
design-patterns × 6
spring-mvc × 6
design × 5
web-services × 5
hibernate × 5
domain-driven-design × 4
api-design × 4
authentication × 4
object-oriented-design × 3
mvc × 3
caching × 3
backend × 3
jwt × 3
rabbitmq × 3
database × 2
unit-testing × 2
multithreading × 2
inheritance × 2