Spring MVC Maven multi module controller is not working - spring

I have spring maven multi module project, in that I have more modules, these modules consists of dao, domain, service, and controllers. I have separate application context XML file for each modules. Controllers in the modules are not working, but controllers present in the web module is working. I had given #Controller in the controller class, and mvc:annotation-driven and context:component scan tags in the spring application context file. Why is it not working?

Related

Component scanning for packages in separate modules

I am building a multi module Spring Boot project.
The intent is not to deploy several applications which share code, but rather to have one application where code relevant to different sections of the business are split into separate jars.
The parent project has <packaging>POM</packaging>.
The modules underneath the parent have <packaging>JAR</packaging>.
The parent pom includes as dependencies each of the modules.
One of modules has the main class which is annotated with #SpringBootApplication
This loads the Spring context correctly, and this class can access classes in other modules\jars when the application is built and run.
However, Spring does not instantiate components located in other modules, annotated (in this instance) with #Endpoint and #Configuration, and their constructors are not being called when the application starts.
The package names in the other modules shares the same structure, so #Components there should be be picked by by the scanBasePackages declaration in the main class which starts the Spring context.
Is there a way to do this?
Thanks

Spring MVC modules,subsystems and components

Let's say we have a Spring MVC project which is a banking web application. I am trying to identify the sub-systems ,modules and components of this project.
1.Subsystems - from what I have red the subsystems in MVC architecture are only 3- the Model,View and Controller is that correct?
2.Modules - are these a group of classes that do something particular as a group.For example LoginController.java,RegisterControler.java form a module let's call it Authentication
3.Components - for components I am not sure which they are in a Spring MVC project.
If someone can explain with examples in terms of a banking web application or other Spring MVC app it would be great!
Spring MVC follows the Model-View-Controller design pattern.
Model - A model contains the data of the application. A data can be a single object or a collection of objects.
Controller - A controller contains the business logic of an application. Here, the #Controller annotation is used to mark the class as the controller.
View - A view represents the provided information in a particular format. Generally, JSP+JSTL is used to create a view page. Although spring also supports other view technologies such as Apache Velocity, Thymeleaf and FreeMarker.
Spring Boot Framework has mainly four major Components.
Spring Boot Starters.
Spring Boot AutoConfigurator.
Spring Boot CLI.
Spring Boot Actuator.
Please check out : https://www.journaldev.com/7989/key-components-and-internals-of-spring-boot-framework
In project-specific terms,
Module: It can be something that can be built separately in an application. ex: Login Module, Sign-up module, Transactions module, etc., You can say a module is a group of components.
Sub-systems: As far as I know, subsystems are the service package related stuff.
Components: Annotating a class with #Component tells Spring that it is available for fulfilling injections.
Spring Component annotation is used to denote a class as a Component. It means that the Spring framework will autodetect these classes for dependency injection when annotation-based configuration and classpath scanning is used

Simple REST service with Spring framework not using Spring Boot

I want to start with the most simple Maven Project with a simple REST resource not using Spring Boot and generate a .war artifact that is deployed in a servlet container. I am using Eclipse IDE. So I would like to know what is the basic things in place needed to create such a Project.
I think I need at least this dependences:
Spring-core, Spring-mvc, Spring-web, Spring-context,
I also need the stuff with a class annotated with the #RestController annotation, with some method annotated with the #Requestmapping and so.
But whats the minimum content I should have in the WebContent directory and its subfolders META-INF, WEB-INF ... in order to the servlet container to know how to use the .war component? I dont want any HTML nor JSP pages.
In your WEB-INF folder, you will need a web.xml file. This is where you will configure your dispatcher servlet. This is the part of your application that receives requests and delegates them to the appropriate part of your application.
You will also need some sort of REST configuration file. You can define beans for Spring and component scan config.
A good explanation of this can be found here, https://www.programming-free.com/2014/01/spring-mvc-40-restful-web-services.html

Role of spring container in spring mvc web application

We are developing a web application which uses spring mvc, rest, jquery, ajax and json. Also we use mongodb as our db. We use maven as build tool.
I have a project structure like below:
eem (parent pom)
eem-db (sub module, and it is a Eclipse project for mongo db dao level and model resides here)
eem-net (sub module, and it is again a Eclipse project for some networking code)
eem-webapp (sub module, and it is a Eclipse web app project for web application, which has Spring MVC)
My doubt is about the design of our web application in which I'm not knowing how to use spring container on this web app.
Below are my requirements and need help:
Is it a correct way to have mongodb related dao in a separate project?
(we use dependency on eem-webapp to get db code (as .jar) on our web app).
How can i use #Autowired on the model in my controller to get mongo db model "emp" (say, com.eem.db.model.emp)? i.e What configuration do i need to provide on my eem-webapp to autowire emp (and all model classes) model to my controller?
I want to instantiate a class (say, com.eem.net.discovery.discover) from eem-net on my controller. How should i do this from spring config file. I know using new is not necessary when we are on spring container. What kinda DI i should use for this situation?
Any pointers for my learning?
The best practique is create one session factory bean (scope=singleton) that you can #Autowired in all your Controllers, you can also create one pool connections to managing your clients db requests.
For this you can create your own .jar, and use your own .jar classes to register your bean in your spring container.

Using Maven & Jax-RS, where do I put my files?

I created a maven project using a Simple Web App Archetype. Then I went in and created a Jax-RS module. Now I have 2 index.jsp. Should I have created my project without an archetype and then added a Jax-RS module?
I also plan to add some persistence to the project. Maybe hibernate.
You don't need index.jsp for JAX-RS. Every JAX-RS servlet (Jersey, RESTeasy, etc.) provides its own Servlet, that dispatches REST requests into your #Path annotated resources. You configure the servlet in WEB-INF/web.xml.
The rest looks correct in your project layout.

Resources