2
I created a modular web project using Apache Maven with the following structure:
proj-build
|--- proj-utils
|--- proj-persistence
|--- proj-services
|--- proj-web
`--- proj-ear
Description
proj-build: This group the modules only for carrying out the chain build in the modules, that is, each project has its own configuration when the build is carried out, without any relationship with this project Parent(proj-build).
proj-utils: This module gathers utility classes such as: Exception Classes, Classes that configure Hibernate Sessionfactory, etc..
proj-persistence: This module gathers entity classes, DAO classes, DAO interfaces. It has dependencies like JPA, Hibernate, etc..
proj-services: This module brings together classes that implement the business logic. It is dependent on the proj-persistence module.
web-project: This module brings together the Controllers classes, HTML pages, CSS pages, Javascript and any other features you need on the pages. Has dependency with proj-services module, Spring MVC, Spring Security, JSTL, Java Servlet, etc..
projector-Ear: This module is dependent on all other modules except proj-build. This module packages the other modules in an EAR package.
My question is: How do I apply the Spring DI/Ioc Framework as a dependency on this modular project? I apply the dependency on all modules or on some specific module?
First thank you for answering me. And just to clarify, in the first case it is about the module
proj-services
, where theimports
so that it is possible to inject the DAO’s and utility classes into the moduleproj-services
from what I understand. Already in the last case, which is the file configurationweb.xml
, is referenced all the configuration files of each module, which is where the container will take all the configuration to interact with all the modules as a whole, so I understood. Correct me if I got it wrong.– klaytonbrito
(NOTE: in the above comment the container I’m trying to say is the DI/Ioc container of Spring) But in the case of the files
pom.xml
of each module, these will be dependent on the artifactspring-context
right? Except for the moduleproj-web
, in which it will be dependent onspring-mvc
, that in a transitive way will have thespring-context
.– klaytonbrito
@klaytonbrito Regarding the first comment. If you use import in a file do not need to declare all on
web.xml
. As for the second, you can declare thespring-context
in all of them, including the web. It is not good practice to depend directly on undeclared dependencies. To avoid redundancies, use a Parent pom with a sectiondependencyManagement
declaring all project dependencies.– utluiz
I get it. About the Parent pom it is good to reuse the
proj-build
? Or is it better to create another module for dependencies? Something else, I created onecontext.xml
which contains the configuration of a Datasource JNDI for database connection and put in theMETA-INF
moduleproj-web
so that it can be used by Spring Security, but thehibernate.cfg.xml
who is in theproj-persistence
you will need to point to the Datasource JNDI of the context.xml, if I use this property then it will work correctly?<property name="connection.datasource">java:/comp/env/jdbc/projbanco</property>
– klaytonbrito
The Parent pom it is better to be a separate project, just for that. At least for me it works better. As for the datasource you can configure Hibernate by Spring (example). There does not repeat the configuration.
– utluiz
Got it, the Hibernate configuration link you passed is very interesting. Thank you very much for the help, man. Your answers enlightened me many things and I learned several new things.
– klaytonbrito