Spring Data JPA project as dependency of Spring Boot project - spring-boot

I would like to have a microservice project using Spring Boot that gets access to Entities and DAOs through a dependency that is created through Spring Data JPA project. The idea is that multiple microservices could get that dependency.
However, when the jar is assembled in the Spring Boot Data JPA project, a lot of dependencies are included in it through starter dependencies. Most them are also present in the Spring Boot Microservice project that uses it.
How would you go about building a jar through Spring Data JPA with just Entities and Repositories? I have not found any clear examples on how to achieve this, not sure If I am off with my thinking or not.
Thanks in advance.

To my view point, sharing domain entities between microservices is fundamentally wrong in microservices architecture.
Please learn about Domain Driven Design modelling. There are lots of articles and videos available on the internet.
Domain Driven Design
Bounded Context
Sharing means no duplication but more coupling.
Duplication leads to less coupling.

Related

Import and use a spring security project in a spring boot project

I'm a beginner in Spring Framework.
I created in two separate projects:
Project "A" for Spring Security and JWT with a DB for User, Permission, Role, etc. Used for authentication and permissions;
Project "B" for Spring Boot with a DB for business tables. Used as a backend for a web-app;
Both projects have controllers and starters (do not import).
I would like to know how to use authentication check ( JWTFilter ) and permissions ( PermissionEvaluator ) from the security project in the backend project.
In the future, I want to use same spring security project for multiple spring boot projects.
If necessary, I can add the basic structure (packages) of each project.
AGGIORNAMENTO
After so much research, Should I separate Spring Security from Spring Boot project and Spring Boot configure and use two data sources threads were very helpful in solving my problem.
However, in my case I didn't need to diversify the dataSource because the DB is unique but with a different schema for the business and security tables.
Then, I added the "schema" key to the spring #Table annotation. Also, to solve the problem for visibility of the repositories and entities I added the spring annotations #ComponentScan, #EnableJpaRepository and #EntityScan
You have two approaches to implement your project:
Deploy all packages of project B in the project A. this approach appropriate for small project.
Similar the approach 1 use the multi module architecture that is a clean way to implement. but in this approach you must set basic package in all of the modules

Convert project from Spring framework to Spring boot

I have a set of projects in Spring framework and I have to Find the ones which can be converted to Spring boot.
Is there anything that is related to Spring framework and cannot be converted to spring boot ? In my research, I Could not Find something like that.
But does anyone know something, like a dependency, which would force the project to stay in Spring framework ?
Spring Boot uses the Spring Framework as a foundation and improvises on it. It simplifies Spring dependencies and runs applications straight from a command line. Spring Boot provides several features to help manage enterprise applications easily. Spring Boot is not a replacement for the Spring, but it’s a tool for working faster and easier on Spring applications. It simplifies much of the architecture by adding a layer that helps automate configuration and deployment while making it easier to add new features.
Most of the changes for migrating Spring Framework application to Spring Boot are related to configurations.This migration will have minimal impact on the application code or other custom components.Spring Boot brings a number of advantages to the development.
It simplifies Spring dependencies by taking the opinionated view.
Spring Boot provides a preconfigured set of technologies/framework to reduces error-prone configuration so we as a developer focused on building our business logic and not thinking of project setup.
You really don’t need those big XML configurations for your project.
Embed Tomcat, Jetty or Undertow directly.
Provide opinionated Maven POM to simplify your configurations.
Application metrics and health check using actuator module.
Externalization of the configuration files.
Good to refer this for migrating from Spring to Spring Boot application: https://www.javadevjournal.com/spring-boot/migrating-from-spring-to-spring-boot/

Spring Data Rest vs Spring Data Rest WebMvc

What is the difference between:
spring-data-rest
and
spring-data-rest-webmvc
To obviously they are two different things, but I am slightly confused here.
The spring-data-rest-webmvc is the project describing the main concepts of spring-data-rest which is the one of the main spring modules.
In most cases one will use spring-data-rest dependency for his/her project.
Use spring-data-rest when your app is based on Spring Boot
spring-data-rest-webmvc when your app is not a Spring Boot app
Ref: https://docs.spring.io/spring-data/rest/docs/current/reference/html/#install-chapter

Spring boot JPA without Spring data

I'm gradually introducing Spring Boot to a Spring JPA project. My intent was to first introduce Spring Boot, than at some later stage Spring Data, but I was not able to find any examples (nor a suitable starter) that uses Spring Boot + JPA without Spring Data.
How come? Is there any benefit of introducing Spring Boot to Spring JPA project, without Spring Data, or does it make sense only with Spring Data in place.
Any article link or example code would be helpfull and appreciated, thanks
More context
I'm working with a live project so every change introduces risk. We're discussing of moving from XML to JAVA based configuration, and I'm advocating adopting Spring Boot at a same time, but I lack persuasive selling points.
Personally, I want to include Spring Boot on all layers to boost future productivity, but I need to argue better the direct immediate benefits of using it in our Service/DAO module which is at the moment based on Spring/JPA/Hibernate with the good old manual CRUD implementations.
So I need selling points for using Spring Boot on a persistence layer, but ones that span beyond Spring Data (e.g. configuration gains, maintenance, testing...anything)
As folks have said above, there is no Spring Boot JPA. It's either Spring Boot Data JPA, or JPA on its own.
The immediate benefits that I could think of:
With Spring Data JPA you don't write the Dao layer. For all CRUD operations, the CrudRepository interface gives you all you need. When that is not enough, all you have to use is the #Query annotation to fine-tune your SQLs
Configuration by convention. For example, with Spring Boot, just having the H2 dependency in the classpath gets Spring to use the H2 in-memory database, gives you Datasource configuration and transaction management (only at the JPA repository level) by default
Ability to create micro-services. With Spring Boot, you can create micro services that can be deployed and run on a number of boxes with java -jar ...
You can enable annotation-based transaction with one simple annotation: #EnableTransactionManagement
Java configuration over XML. This advantage is not to be underestimated
A lot less code (the DAO layer) means also a lot less maintenance
The native ability to provide a RESTful API around data: https://spring.io/guides/gs/accessing-data-rest/
It all depends where your company is heading for. If they want to deliver business value faster and move towards more a DevOps operating model, then the above advantages should be enough selling points for any organisation
Spring wiht JPA (for example Hibernate) but without Spring-Data-Jpa means that you direct interact with the JPA Entity manager and. Typical you use it to implement your own DAO from it and use the #Respository annotation.
#Respository
public class UserDao {
#PersistenceContext EntityManager em;
public User findUserByLogin(Sting login) {
....
}
}
Even if there is no starter project, you could use a Spring-Data-JPA project, and implement the Repository in this old fashion style. (And then you could show how simple it become when you just write Spring-Data-JPA interfaces)
As far as I known, spring-boot means more convenient not any independent business feature.
In other words, spring-boot helps you to start, configure your application in some automatically way. But you can do that without spring-boot with your own specific configuration.
So, you are going to use spring-boot in your application means you are going to use spring-boot's auto configuration feature with your original application.
Actually, Spring JPA implemented in spring-data-jpa is what you are looking for not spring-boot. Of course, spring-boot can simplify your work dramatically.

adding spring-data-rest ontop of spring-data-jpa

i created a maven project, and added all dependencies i need.
i have some repositories using the spring-data-jpa, and i added some integration tests.
now i need to add ontop of it spring-data-rest, if i understand it is based on springmvc.
but all examples i found, i need to add spring boot to start the app.
i noticed also all new spring projects use spring boot.
this means that i have to learn and use it for my projects?
how can i use spring-data-jpa+spring-data-jpa with an existing servlet3 project
The reason all examples are written using Boot is that Boot is indeed the way you should start a new Spring project these days. It free's from a lot of the tedious work of setting up the infrastructure, finding dependencies in the right version etc.
To use Spring Data REST without Boot, simply add the necessary dependencies to your project. The easiest way to do this is to use the Spring Data Release Train BOM (which will help you pulling in the correct matching versions) along side the version-less dependency declarations for Spring Data REST WebMVC and - in your case - Spring Data JPA.
Then go ahead and either register RepositoryRestMvcConvfiguration as Spring bean (either through XML configuration or JavaConfig).
All of this is also documented in the reference documentation.

Resources