Spring MVC + Web services + Hibernate project structure - spring

in .net it is possible to create webservices, asp.net MVC, ORM, DTO, BAL as different projects so that we can reuse them nicely. For this college project I have been force to use j2ee and I am wondering how to do this layering. Is it possible to create hibernate as a different project? or how should I handle this?

I don't know .net at all, but you can start by creating multimodule maven project in eclipse.
1 module will contain you Entities and Dao and procude a jar,
1 module will contain #Controller and object related to your web service and
produce a war or ear.

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.

Mixing spring 3 and 4

I have a legacy application that uses Spring 3.x. It's built using Maven and creates a war file. It's big, perhaps what would be called a monolith nowadays.
I'm slowly moving to a micro services architecture and as a first stage I'd like to create Maven sub-projects built as JAR files (within the web application) that contain Spring controllers that use the newer #RestController annotations of Spring 4.
Will there likely be problems do you think of mixing version 3 and 4 of Spring? I'd like to scan the package structure of the jar file from the existing Spring 3 app in order to detect the Spring 4 annotations.
Thanks in advance.

Integrate New Spring MVC framework for coming module and struts 1 and hibernate 2 based existing framework in single web application web.xml

Currently I am working on struts 1,spring 2 and hibernate 2 based web application.now we are going to add some more module in our application but the requirement is that we have to integrate new module with spring MVC framework without doing any changes for existing module.
So how can i integrate new spring MVC framework and existing framework in single application together ?
What changes i have to do in web.xml file ?
So is it possible to use (hibernate 2 and hibernate 4) jars and (spring 2 and spring 4) jars in single application ?
If it is possible then what about hibernate session factory , how this is going to be handled ?
Its quite bad idea I think. Especially packing different versions into one jar may cause several compile and runtime problems. You shouldn't do it.
Two different MVC frameworks for one web application is probably not impossible but also very bad decision.
If you cannot drop existing code/project, you should start with clean new seperate project and try to configure them to run side by side on production. But no mix up.

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.

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