Struts + Spring + Hibernate integration - java

For example, we have the next bunch: Struts, Spring, Hibernate. Can you help me understand the role played by each of the elements?
I know that Hibernate is responsible for all on the database.
But, what role Struts and Spring in this case?
Thanks.

Struts is web application framework - used to give you the possibility to expose your application through web interface without dealing with low level classes. When using struts you should be careful as there often bad advices on using you application logic inside struts classes. Don't do this, struts is just web front-end.
Spring is general application framework that in first place helps you decouple classes from one another using dependency injection. But this is not the only reason for using spring, it provides tons of other features: http security, aspect oriented programming, out-of-the-box integrations and support of different frameworks. So this gives you a fast start on using different technologies.
Hibernate is object relational mapping. Using it you map your classes to database relations and avoid working with SQL requests.

My guess:
Struts is used for presentation purposes. Spring is used for AOP, and Depency Injection. Hibernate is obvious: persistence.

Spring:
Dependancy injection
Transaction Management.
Open Session in View Filters
Spring Security.
or in other words nice clue to between application layers.
Struts:
Model and view Design pattern.
Simplifies web flow.

Struts is for webapplication preparation. It has great form validation f/w, and tiles f/w to create webapplication in a great way.
Spring has 6 modules. It provides abstraction on the java-j2ee application. Spring MVC provides abstraction for struts.

Related

Is there any annotation based version for spring web flow?

I have been working on an infrastructure project that has a myriad of pages that used in numerous flow based scenarios. I eager to use a standard framework for facilitating this flows. I have a glance on spring web flow and I realize it is difficult to deal with all of the XML stuff like flow files. Could you please tell me is there an annotation base version instead of these XML files? Or Is there any other frameworks that use annotation based approach for this purpose. Moreover, I saw Seam framework, but like Spring Web Flow it has an XML based feature. Additionally, I read some articles about Netui Page Flows. Even though it has annotation based flows, as you know it is a very old framework and discontinued now.
I use this links:
spring web flow support in intellij idea 12
Spring Web Flow Ref Book
spring web flow
As I need this xml based file for create a web flow for my JSP pages into my enterprise application, after month looking for best solutions and frameworks, finally I find Spring Statemachine for my porpuse. I put that here for someone in future that looks for object-oreinted state machine that can be used in her/his page flow.
Thank you Spring :)

spring framework role in mvc

It's a question about Spring Framework and its architecture. I have read a lot about Spring in the middle-tier or in the layer scheme. But, I need to know which is the role of this framework inside the MVC pattern.
I must clarify I'm not talking about Spring MVC, but about the entire framework.
For example:
View: JSP, JSF, etc...
Controller: Servlets, Spring?, etc...
Model: Spring?, Hibernate, JPA, etc...
I donĀ“t know where can I locate this framework.
If you use Spring Framework (context, core, aop, tx, jdbc) for inversion of control, transactions, aspect oriented programming, JDBC support you definitely use it in M.
If you use Spring MVC for your web controllers you definitely use it in C.
If you use Spring jsp tags, you also use it in your V.
Below url would be helpful to you.
http://www.tutorialspoint.com/spring/spring_overview.htm

Spring MVC vs JSF [duplicate]

This question already has an answer here:
Difference between Request MVC and Component MVC [closed]
(1 answer)
Closed 6 years ago.
I haved used Struts framework in all my past applications and for the new application,my client has requested to use either Spring MVC or JSF? I am not familiar with these two frameworks but our timelines are strict. So, I am not sure which framework I will choose to build the application.
Can anyone please suggest me which framework will be easy to learn in quick time?
Thanks
Of course, it's going to be different for everyone, but I'd suggest Spring MVC, as it's a request-based framework like Struts. Of course, you'll want to learn about core Spring stuff like Inversion of Control / Dependency Injection (but I'd consider that a plus...) and whatever you're going to use for database access (just JDBC? Hibernate? iBatis? etc.).
JSF is component-based, which is a bit different paradigm from request-based frameworks. If you do plan to go the JSF route, I'd suggest looking at Seam from JBoss. It's more of a front-to-back framework that uses JSF as the web/presentation end and EJB as the backend. And pretty much all the people who've used it claim it makes JSF and EJB more usable than they are by themselves.
Good luck on whichever technology you choose, though. (Sounds like you'll need it - strict timelines and a client that's prescribing web frameworks?)
I'd suggest SpringMVC, because of the timeframe:
you need something with less steep learning curve. SpringMVC is more like Struts than JSF
in order to use the power of JSF you need to get familiar with many "tricks", while SpringMVC is more or less straightforward
I'd suggest JSF + Primefaces component library. I am using this combination to build most of our projects. As I remember, I spent one week to learn the technology and finished my first project in one month. The development time at least 30% faster than Struts.
SpringMVC is not a bad technology and it's quite popular.
Really depends on which one your like the most.
JSF is just the view layer of the MVC and wil need to be used with other technologies like Spring/Hibernate or EJB for a full MVC.
I have been using the Spring MVC for about 1 months now, whilst it's probably not the latyest version of SpringMVC I've found it a little annoying that we have so much XML to deal with. All the managed beans and DAO has XML config to it. Also everything seems to have to go thorugh a method called onSubmit().
JSF with something like EJB is far simplier in my opinion... Everything can be done using Annotations so simply use #ManagedBean=theBean in your backing bean and in your JSF put {thebean.param} and you have access to the backing bean's data. Also you can use the Session beans of your EJB as the backing beans for JSF then have direct acces to the DAO (Model layer) Entity bean. Again simply by using the #Entity annotation and the EntityManager class
Spring MVC is a web framework inside the Spring framework. It does provide features as those in JSF 2.0:
ajax-support
validation
dependency-injection etc
Yet, you can use Spring (not Spring MVC) together with JSF 2.0, with spring providing the dependency-injection, aop, transaction management mechanisms, and JSF providing the web layer.
Of course, you'll want to learn about core Spring stuff like Inversion of Control / Dependency Injection (but I'd consider that a plus...)
JSF is indeed based on IoC, and much simpler than the Spring learning curve.

Can anyone recommend a Java web framework that is based on MVC and supports REST?

We are looking to host a Java Domain Model (written using DDD) inside a web application. Ideally I would like to support RESTful resources and requests, having a single site to support both users and a REST api.
Ideally the same url could be used for both end users and the RESTful API of a given feature (with HTTP content types / negotiation specifying the difference).
I have done similar apps in Ruby on Rails and Asp.mvc, but have no experience doing anything like this in Java. Anybody have an experience or advice on where to start ? (Googling suggests that Spring v3 might be an answer, anybody have any thoughts on Spring 3 ?)
Spring 3 is not quite ready yet, but the current milestone build (M3) is stable enough to use for real. We're using its REST support in a production application already. It's pretty goodm, and integrates very nicely with Spring MVC. It's not JAX-RS compliant, but I don't see that as a problem.
Restlets Framework http://www.restlet.org/
I've used this framework extensively, easy to use, really flexible and supports loads of features and more you'd expect from file upload to gzipping responses.
This module has Spring support too, really easy. For example:
web.xml
<servlet>
<servlet-name>webapi</servlet-name>
<servlet-class>
com.noelios.restlet.ext.spring.RestletFrameworkServlet
</servlet-class>
</servlet>
spring context
<bean id="root" class="org.restlet.ext.spring.SpringRouter">
<property name="attachments">
<map>
<entry key="/{variable}/your/restful/call/{variable2}">
<bean class="org.restlet.ext.spring.SpringFinder">
<lookup-method name="createResource" bean="yourBean" />
</bean>
</entry>
</map>
</bean>
Framework also has a great documentation, first steps for newbies and a great WIKI.
This framework is very mature and actively improved, checkout the up and coming features.
It's also very easy to unit test your Restlet Resource endpoints using jmock.
Hope that helps.
For web services, Jersey is nice and easy. Spring 3 sounds like it will be good, but it's not out yet, and Jersey is full featured and supports SOAP and JSON out of the box. It's all annotation based aside from adding the servlet to your web.xml file which makes it probably easier to configure than even Spring plug-ins, but to avoid getting yelled at, I'll say maybe not.
For (MVC) web pages (user UI), I use Spring MVC or Struts.
Spring is great. I've used it for some projects and recently also together with Liferay portal server for developing a portlet.
Why is Spring good?
It is a non-invasive framework: This means your application code doesn't depend on the framework (uses the IoC - Inversion of Control - concept). Spring does just what a good framework should do: support the development and not create further dependencies.
Dependency Injection: Spring uses the dependency injection concept which is great for avoiding dependencies on your code. You will define the dependencies in a spring xml configuration file where you define your beans and connections/relations among beans. This greatly facilitates reuse, lowers strong coupling among your objects which leads to better maintainability of your code.
It's not just a web framework: Spring MVC provides a lot of different controllers which are suitable in different contexts. But it isn't just a web framework but it supports the development on all the different layers (presentation, service and data access layers). For instance on the data access layers it nicely integrates with ORM mappers like Hibernate and it uses Aspect-oriented approaches for providing transaction management.
Lower-coupling -> increases testability: By avoiding strong coupling, the testability of your code will be increased. You can nicely inject mock objects for testing the different layers.
All in all, I just had positive experiences, because Spring really promotes best practices.
I m a monorail MVC user ( castleproject.org), so i guess we come from a similar background.
A few months ago we started working on the java stack in a different project, particularly with Spring.
Feature wise it s got 90% of what I m used to in monorail, however It is much more flexible, the downside to that is that there is a lot of configuration to get used to.
Documentation is extensive sometimes too much so you dont know where to find something.
Hope it helps

How does a java web project architecture look like without EJB3?

A friend and I are building a fairly complex website based on java. (PHP would have been more obvious but we chose for java because the educational aspect of this project is important to us)
We have already decided to use JSF (with richfaces) for the front end and JPA for the backend and so far we have decided not to use EJB3 for the business layer.
The reason we've decided not to use EJB3 is because - and please correct me if I am wrong - if we use EJB3 we can only run it on a full blown java application server like jboss and if we don't use EJB3 we can still run it on a lightweight server like tomcat. We want to keep speed and cost of our future web server in mind.
So far I've worked on two Java EE projects and both used the full stack with
web
business logic
factories/persistence service
entities
with every layer a seperate module.
Now here is my question, if you dont use EJB3 in the business logic layer. What does the layer look like? Please tell what is common practice when developing java web projects without ejb3? Do you think business logic layer can be thrown out altogether and have business logic in the backing beans? If you keep the layer, do you have all business methods static? Or do you initialize each business class as needed in the backing beans in every session as needed?
EJB3 is split into two layers:
persistance (JPA, old Entity beans)
business logic (old Session beans)
You can have the same architecture, without using explicitely EJB3.
Persistance
JPA is very close to Hibernate. We use, and prefer it to JPA.
The annotations come from JPA, but there is no need for a container, it's not really EJB.
Business
Spring also is very close to the Business layer of EJB3. With many more capabilities...
Some even say they are better than EJB3 !! ;-) They say that EJB3 was created from these two solutions (but still have to reach at their level on many points!).
EJB enhanced a lot over the last 5 years. Especially with version 3 they became a lot more lightweight.
Java EE 6 has a web-profile that makes it possible to even run on a tomcat server a Java EE stack. http://www.oracle.com/technetwork/java/javaee/resources-jsp-139799.html
Further it is possible to install all the necessary components on tomcat:
http://tomee.apache.org/apache-tomee.html
I have an example project including EJBs on github that shows how to use them:
https://github.com/ManuelB/facebook-recommender-demo
Further I would recommend the screencasts of Adam Bien:
http://www.adam-bien.com/roller/abien/
If redeployment times are the reason why you aren't using EJB you should look into:
http://zeroturnaround.com/software/jrebel/
To still answer your question you should look into the following Java Web Frameworks as EJB alternatives:
Apache Wicket https://wicket.apache.org/
Apache Tapestry http://tapestry.apache.org/
The play framework http://www.playframework.com/
Spring http://projects.spring.io/spring-framework/
People that don't use EJB usually use Spring or another dependency injection framework. JSF allows you to create beans and wire them together, however it would be better to use this only for the UI and use Spring for your business layer. A lot of information is available for integrating JSF with Spring.

Categories

Resources