How to share spring boot multi modules project (A) as dependency to another multimodule spring boot project (B) to access all rest api from it? - spring-boot

How to share spring boot multi-modules project as dependency to another multi-module spring boot project to access rest api from it?
The use case is :
I want to share the rest APIs from the multi-module Spring boot project let's say "A" to another multi-module spring boot project "B" as maven dependencies.
In this case, each module has different API's that needs to be accessed from Project "B"
Each module can be shared with its dependent module to run all the implemented rest api to another project. In simple words, all the project "A" RestControllers class should be accessible from consumer project "B".
When I tried to share it as jar of project "A" to Project "B" it does not throw any error but it should recognize the API endpoints from "A" with the message "This application has no explicit mapping for /error, so you are seeing this as a fallback. There was an unexpected error (type=Not Found, status=404)."
I also tried to add #ComponentScan(basePackages = "com.demo") in configuration but still it did not work.
I found Related question but in my case its multi-module project
Please feel free to ask for any additional information if my question is not clear.
Thank you in advance.

Related

Spring boot app in another project from controller class

I want to know if I can keep my Spring boot class in Project A and my controller and services in Project B and invoke the end-points from Project A? The reason to do this is because I want to give Project A (which has dependency of Project B) an option to extend my controller and services to override any method.
Yes, it is a common practice to have your starter in a project and the libraries in another (spring projects are a good example for it).
it is better to have them separated in 2 repositories :faster build, version management, separation of responsibility between team members etc.
Build the project with the libraries (A)
Project with the starter (B) will have a dependency to project A
In general, it is recommended to have a configuration in project A with #ComponentScan and project B should import the configuration.
If the beans are scanned from project A, you will have access to all endpoints and services.

Spring Boot web app without maven

Friends,
I am trying to build a Spring boot project. but the challenge is maven isn't working in office environment(basically proxy isn't allowing).
Is there any way to create a spring boot project without maven?
if I can get any boiler code link would be very helpful.
Yes, it is possible. Just add all the necessary jar in project class path manually. Example Spring boot project jar added by gradle.
Part1
Part2

Configuring Spring security with spring boot on already created project, IntelliJ

I have previous experience in Spring MVC but I am new to Spring Boot.
I am Using IntelliJ for the first time.
What I noticed is that when you create a Spring boot project with security dependencies added during the time of creation, Then the IDE creates the project already configured With Basic Authentication whereas if I add dependencies to pom.xml after creation, then the application won't get configured with basic authentication automatically.
Can anyone explain this behavior of IntelliJ and can anyone help me with steps for configuring the pre-created project with Basic Authentication?
IntelliJ is using
https://start.spring.io/
to initialise your project. After the project is initialised, the IDE doesn't modify your code in any way. That is the normal behaviour and it is not Spring Boot related.
NOTE: The dependency that you add in your pom.xml is just pulling down that dependency, but if you need to use it you do the code yourself. (More information about Maven: https://en.wikipedia.org/wiki/Apache_Maven)

Spring Boot support maven multi-module

I am trying to convert my existing multi-module maven Spring project to Spring Boot project. The reason is make it self contain and follow Martain Fowler's microservices concept.
However, the problem I have encounter is when try to clean build, seems the spring boot is trying to find the Main method from every module, which of course will failed.
Is this feature currently supported by Spring Boot 1.1.6.RELEASE or I did something wrong?
Thanks
It sounds like you've added Spring Boot's Maven plugin to every module in your build – it's what's looking for a main method. You should only add the Spring Boot plugin to a module if its a service that you want to run. If the module's just code that's shared between your services, the Spring Boot plugin isn't needed in that module.

How to setup a Spring multimodule project?

I'm new to Spring and try to setup a project which is split into 3 submodules. As build tool I'm using maven. My problem is, that I don't know where to add Springs "magic".
My 3 submodules are "ORM" (holds all the hibernate staff to access the database) "BusinessLogic" (which should hold the complete logic) and "WebApp" (adds as the only "client" to the app / logic).
I want to use SpringMVC for the WebApp which seems to be no problem. As "BusinessLogic" should hold the complete logic I thought of adding the Spring related stuff (Bean definition / DI) in that module. But then I don't know how to setup Spring when accessing the module form the webapp.
The hole project is being ported from a JavaEE / JBoss app where "ORM" and "BusinessLogic" (implemented as EJBs) where put into one .ear archive and the webapp into a seperate one (.war). JNDI was used to access the beans from the webapp, but I completely want to decouple the application from JBoss and deploy it on a Tomcat webserver.
At the moment I've created all three modules as separate Maven projects ("ORM" and "BusinessLogic" as .jar, "WebApp" as .war packaging), linked by a "parent" project.
Thanks for any hints on project setup :).
Greetings
Ben
you could configure spring context in your web.xml and you can perform import of Spring sub-modules context. You can add import's configuration of sub-modules in your webApp application context.

Resources