how does actually spring integrates with struts 2 - spring

I am new to Struts and searched online for tutorial and examples that shows integration
of spring with struts 2.
Some examples talk about using struts spring plugin in struts-config.xml and some dont even have struts-config.xml file.
This is making me confused.
So if any one can tell me whats the latest way for this.

Check the docs, it has a dedicated chapter on Spring <=> Struts 1 & 2 integration

First you need to clarify if you're using Struts 1 or Struts 2--the answers are very different on the Struts side.
On the Struts 2 side, there's a Spring plugin which essentially delegates all Struts 2 object creation to Spring, so you get all of the Spring wiring and so on without having to change any of your application's code or config.
In Struts 1, you'd generally declare your actions to be of the org.springframework.web.struts.DelegatingActionProxy class in your Struts 1 config file. In the Spring config you define a bean whose name matches the path, and is a Struts 1 Action subclass.
Struts 2's config file is "struts.xml" by default, but is configurable. Struts 1's config file is (again by default) "struts-config.xml". Either can have multiple config files.

Related

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.

Using Spring with JSF/Facelets [duplicate]

This question already has answers here:
Using JSF as view technology of Spring MVC
(3 answers)
Closed 7 years ago.
I would like some clarification on some things.
I have developed a web application in the Eclipse IDE using JSF and facelets (xhtml web pages). Now, my manager told me to re-create this application but as a RESTful web application using Spring.
I did some research on Spring MVC and its DI/IoC features and have a few questions:
I see that Spring offers DI/IoC, does JSF not offer that?
Can you create RESTful web apps in JSF?
Since JSF uses beans just like Spring, what advantage is there to use Spring over JSF?
Are the facelets just the view part of the Spring framework?
Can I use Spring IoC/DI with facelets?
I am starting to think he just wants me to keep the project as is but add the IoC/DI of Spring.
As you can see, I am quite confused on this subject and would like some clarification.
I can understand your confusion. Once I did a project in which I used JSF as front end and Spring MVC as backend.
for you the answer is Yes , You can do inversion of control using JSF by using JSF Beans (for instance managed beans) but you need to keep in mind couple of things.
1: You need to register beans both for JSF and Spring.
2: Its recommneded that you should set same type of scope for this bean in JSF and Spring.
for example: if you are setting request scope for a specific bean in JSF then you should also set Request scope for the same bean in Spring. Only view scope will not be available in Spring but you can write custom view scope which is not big deal
Answer for the part of question Are the facelets just the view part of the Spring framework?
No, you can't say it is part of spring, facelets are handled by JSF but yes , they mostly used as a view part. So when you have a plan to make a application with JSF and Spring then I will interpret it as you are using JSF for front end and Spring for backend.
Restful services using JSF:
Yes, you can make restful service using JSF. here it is very good blog regarding thisRestful web Services in JSF You can also create restful web service in Spring Rest Web Services in Spring

Spring Boot with Jsf views [duplicate]

I am currently implementing a small Spring MVC PoC, and I would like to use JSF as the view technology since most people in my company are used to a J2EE with Primefaces environment.
Does Spring MVC 3 support JSF, or simply JSP? I have read multiple articles mixing the two.
My need is to create an appealing UI. Is there a simple way to do this using Spring MVC with the JSP as the view technology?
Our application uses schedules/calendars in multiples pages. It's basically a time management APP
You're making a conceptual mistake. JSF is not a view technology. JSF is a MVC framework. Exactly like as Spring MVC, albeit they have both a different ideology; JSF is component based MVC and Spring MVC is request based MVC. Thus they are full competitors. You cannot mix them. You should choose the one or the other. Instead, JSP and Facelets are true view technologies. Since Java EE 6 (December 2009), JSP is deprecated and replaced by Facelets (XHTML) as default view technology for JSF.
You can use Spring MVC with JSP view technology. You can also use Spring MVC with Facelets view technology (and many others). But you can not use Spring MVC with JSF components let alone with JSF component libraries like PrimeFaces. JSF output components may work, but JSF input components won't work at all. Spring MVC has already its own <form:xxx> tags for input. Even if you mix them, you will end up with half of the functionality from both frameworks in a mingled and confusing code base. This is not making any sense. If all you want is to use the same UI as PrimeFaces, just grab jQuery UI. It's also exactly what PrimeFaces is using under the covers. PrimeFaces is a jQuery-based JSF component library.
From the other side on, it can also be very good that you confused Spring IoC/DI with Spring MVC. Spring IoC/DI is in turn usable together with JSF. You can replace the JSF managed bean facility (#ManagedBean and friends) by Spring managed bean facility (#Component and friends), usually with the sole purpose in order to use #Autowired in a JSF backing bean. But that's it. The JSF MVC framework lifecycle, the JSF components and the view technology remain unchanged. The standard Java EE equivalent of that would be using CDI (and EJB).
The same story applies to Spring Security. You can use it together with JSF, you should however not follow Spring Security + Spring MVC targeted documentation/examples in order to configure it, but only Spring Security + JSF ones. Do note that Spring Security constraints on business actions only works when you replace the JSF managed bean facility by Spring managed bean facility. So that would still require a "Integrate Spring in JSF" as described in previous paragraph. The standard Java EE equivalent of this all would be using container managed security (JAAS/JASPIC) via <security-constraint> entries in web.xml.
The same story also applies to Spring WebFlow. You only also need to make sure that you're using most recent version of Spring WebFlow as older versions cause conflicts when used together with multiple JSF component libraries. Moreover, since JSF 2.2, new Faces Flows feature was introduced as part of standard Java EE API, hereby basically making Spring WebFlow superfluous.
Then there is Spring Boot. This does not have a direct equivalent in Java EE. Spring Boot basically enables you to execute a Java EE application using a plain Java application class with a main() method "in an easy and abstract way". Without Spring Boot it's surely possible (otherwise Spring Boot would never have existed), it's only a bit more work as to configuration as you have to take into account server-specific details based on its documentation. For example: Undertow and Jetty.
Coming back to JSF and Spring MVC, if really necessary, you can safely run Spring MVC and JSF next to each other in same web application, but they won't interoperate in server side. They will run completely independently. They will at most touch each other in the client side, if some JavaScript in a JSF-generated HTML page happens to invoke a Spring based REST web service call in the same web application. But that Spring web service would then not need/have to know anything about JSF in order to respond accordingly. The standard Java EE equivalent of that Spring REST webservice is JAX-RS.
The upcoming Java EE 8 will come with a new request based MVC framework, named just "MVC", based on lessons of both JSF and Spring MVC, hereby supplanting Spring MVC and providing a standard alternative to JSF.
See also:
What exactly is Java EE?
Difference between Request MVC and Component MVC
What are the main disadvantages of Java Server Faces 2.0?
What is the need of JSF, when UI can be achieved from CSS, HTML, JavaScript, jQuery?
When is it necessary or convenient to use Spring or EJB3 or all of them together?
Spring JSF integration: how to inject a Spring component/service in JSF managed bean?
Why Facelets is preferred over JSP as the view definition language from JSF2.0 onwards?
Spring MVC and JSF don't really mix. You can use JSF for the view related stuff and have Spring manage and wire the backed (services, daos etc.). But trying to match #Controllers with JSF pages isn't something that really works nicely (next to that both are different stacks request based against component-based).
To integrate Spring with JSF you will need to add the SpringBeanFacesELResolver to your faces-config.xml. That will lookup beans from Springs application context. For this to work you have to use plain JSF annotations and not the CDI based annotations.
Spring Webflow can be a help here. Check out this sample project.
https://github.com/spring-projects/spring-webflow-samples/tree/master/primefaces-showcase

DWR 3 integration in Spring 3 environment without XML

I started a new Spring project without any XML configuration file. I become a big fan of annotation config. So I tried to include DWR library, which I used in my last projects. But I cannot find any tutorial, how to integrate DWR 3 in an java config spring environment.
Is this already possible, or can somebody recommend another solution where I dont have to use XML configuration files?
You can follow below two links.
Sample codes are also in the link
http://krams915.blogspot.com/2011/01/spring-mvc-3-and-dwr-3-integration.html
Spring 3 MVC integration with DWR with Annotation

Can we integrate Struts 2.0 with Spring 3.0 +

I am new to Struts . Can we integrate Struts 2.0 with Spring 3.0 + . I am hearing people say "it is not possible to integrate it". Is this true .
If so is there any tutorial on the web having an example ?
edit :
There is a plugin to integrate Struts 2 and Spring 2 (struts2-spring-plugin-2.0.11.2.jar) . Do we have similar one for Struts 2 and Spring 3
Well we always can use Spring 3.x with Struts 2.x and Struts2.x has already a plug in in place to accomplish this.
here is the link Struts2 spring Integration
Struts2 use its internal DI for creation of Actions,Results,Interceptor using the plug in will delegate the call of creation of these key objects to Spring DI.
hope this will help you
edit
The Strus2 Spring Plug in works well even with Spring 3.x and we are using this in our current application it actually use your Spring jars and you have to place them in the lib.This plug in just overrides Struts2.x Object factory which is responsible for creating struts2 core component.
So just go ahead do some experiment with it and if you face problem in integrating you can always post queries here
The Spring 3.0 documentation for Struts 1.x and 2.x is here.
It's technically possible to integrate Spring with really just about anything. For example you can use the IoC container from anywhere in your code by constructing a new ClassPathXmlApplicationContext and passing in a standard context XML resource on the classpath. There's generally not a need to do that though, as it integrates pretty well with most web frameworks. It is however convenient to use for unit tests.

Resources