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

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

Related

Spring Data JPA project as dependency of Spring Boot project

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.

Is there any possibility in swagger2 to create a centralized swagger document for two different spring boot projects?

I have two spring boot projects namely A and B. Now, I need to create a centralised swagger document for both A and B projects. Any ways to do it other than with maven multi-modules?
Thanks in advance

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

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.

Spring: Injecting services from a different project

In the project our team's working on, we currently have 3 separate Spring projects which utilizes the same services. To avoid redunancy and code copy-pasting, we're planning to create a "common" project wherein all the three projects would be dependent on the common project. In this instance, is it possible to inject these services (perhaps using the #Service annotation) to the Controllers of the Spring projects?
EDIT:
I tried implementing this on my own and what I basically did was I configured the pom.xml to get the Spring Context 3.1.1 dependency (which are also being used by my Spring projects) for my "common" project. With that, I was able to annotate my service with #Service. Afterwards, on my Spring project, I set the component-scan to a level wherein my two projects would meet. On my Spring controller, I #Autowired the service from the "common" project. I ran the Spring project and apparently it worked. Is this the best way to do this?
That's absolutely fine, and standard. Spring (unlike CDI) couldn't care less whether your beans come from the current project or from an imported jar.

Resources