Can Spring MVC be used to implement MVC pattern in Swing applications? - java

I was wondering if Spring MVC can be used to implement MVC pattern in Java Swing Applications. I've done some study and found Spring MVC to be used for web development.
Is there any way Spring MVC to be used with Swing Applications?

Not really. As you say, Spring MVC (or Spring Web MVC) is primary targeted for web server development and thus have little to do with client side or standalone GUI applications.
That said, nothing prevents you from using ordinary Spring technologies for dependency injection, as a backend in your model, etc. Spring provides abstractions for persistence, remote network communication, transactions, security and so on that might come in handy in many projects.
Additionally, there is the Spring Rich Client Project that was released some years ago, but I do not know its current status.

No, but you may want to take a look at Griffon, which offers a Swing MVC framework base on Spring libraries and the Groovy language, which should be really easy for any Java programmer to pick up.
I've used it quite successfully to build rather large desktop applications for corporate clients.

Related

Evaluating differences between EJB Enterprise application and Spring MVC framework?

Suppose I have to create a shopping cart website, it should accept lot of requests and process their request without any performance issue. Which method I can use EJB Enterprise application or Spring MVC framework..?
I don't think the two are mutually exclusive. Here is a good discussion on coderanch that really helped me.
http://www.coderanch.com/t/317507/EJB-JEE/java/EJB-MVC-pattern
Hope this helps.
The well asked question IMHO would be Spring MVC vs JSF as the view part of the Java EE stack is currently JSF.
IMHO both are server centric (pages are built on server side) and quite obsolete now, I would personally go on a server part exposing a rest API consumed by a html5/javascript client.
Both Spring and Java EE stacks are well suited for building rest services (Using Jax-RS for Java EE or one of theses approaches for Spring).
I would personally go with the Java EE stack as I prefer by far CDI to spring DI anyway just keep in mind that Java EE is the standard way but spring probably evolve faster.
Have a look to this before choosing.

Spring MVC with a rich client framework

I have several applications that are structured as follows
DataComponent
WebComponent
ThickClientComponent
WebServices
The DataComponent has all the functionality required to access the application's data so it contains the DAOs and the JPA entities. The other three modules are:
WebComponent - A spring MVC application that uses the DataComponent for data acccess
ThickClientComponent- A Swing application that uses the DataComponent for data access
WebServices - A SOAP based services that also uses the DataComponent.
All three projets have the DataComponent as a dependeny in their Maven POM file.
I would like to use a rich client framework like RichFaces, icefaces or primefaces as i need to be able to use the rich components are available in rich client frameworks (i.e. trees, panel, drag and drop etc).
I have looked around and i cant seem to find an example where a Spring MVC application uses a rich client platform. Is it possible? Are the rich client platforms a framework meaning that i have to use either Spring MVC or the rich client platform but not both?
The DataComponent module is spring based.
I suggest you to go for GWT. It is a very good rich client framework and it has a very huge set of components available including drag-and-drop. Also it provides the integration with Spring Framework. You can check out this and this links to know more about its integration.
I have also used smartGWT that is extension of GWT components in one of my project that has backend in Spring framework.
Hope this helps you. Cheers.
Maybe this module will sort you out:
http://static.springsource.org/spring-webflow/docs/2.0-m1/reference/spring-faces.html
You can try ext-js for creating your client side interface. It's heavily java script / ajax based, but that would probably meet your needs. It doesn't really care what your backed tech is, since it works entire through javascript and ajax.
Yess you can use Spring MVC with PrimeFaces but you have to use it with the spring JSF 2 implementation.
If you are thinking to use some faces framework definitely use PrimeFaces.
You could use SpringMVC with JSF but I also recommend to you not to use SpringMVC JSF implementation. Use insted the MyFaces JSF 2 implementation with Primefaces and then link the backing beans with spring.
From my experience this is the best.
But I guess any other options are fine too.

Can't we use spring for distributed java applications?

This came as an interview question.
The interviewer asked me if you can use spring for all the purposes and get away without using any of the Java EE framework .
I said yes, but he asked me how about if the application is distributed and what is the point of application servers.
I am not sure about the answer.
Does Spring do everything that the Java EE framework does?
Well, Spring is wide. So you can review point by point. I'm not specialist in Java EE but I'm sure Spring can cover a lot (if not all) of Java EE concerns. And I'm pretty sure Spring can handle most of layers/concerns in an application.
First of all, Spring IOC. You can configure an object graph with Spring IOC. It helps at any layer configuring all the components you need to implement a layer.
Spring-MVC-Web: you can configure an MVC web component in order to handle and serve all web application requests. I think you can make something cool with it. Configure web responses and its necesary configuration with other business elements (including IPC - Inter Process Comunication).
Spring Security is heritage from Acegi. It's a web framework for defining role-defined access to web resources.
I'm not sure if Hessian is Spring's too. Anyway it's lightweight and it helps comunicating with components in other processes à la RMI.
Well... I'm not sure about persistence, but I thing Spring has templates for JDBC, Hibernate, and all, so it can help anyway (as suggestions indicate: JmsTemplate and RestTemplate are available for communication with other business components!).
The core thinking here is: you can make an app from scratch, so in all cases, Spring can provide a framework to ease the difficult/repetitive tasks on every layer. Does Spring does it? Yes.
Please check other features to see if Spring has something for it. I'd bet it.
Deep down, Java EE is a set of specifications (some of which have been contributed by Spring team!)
Spring's mission statement is to 'Simplify Java Development'
It does so using the following techniques:
POJO -> facilitates easy testing
DI -> promotes loose coupling
AOP -> promotes separation of concerns, maintainability etc
Templates -> provides a standard programming model which does the heavy lifting for you
Spring and Java EE do not have a "Vs" relationship.
Using the above techniques, the Spring Framework lets you build (Java EE) standards-based applications more efficiently.
>Does spring do everything that the Java EE framework does ?
Based on what I've said above, the question might be rephrased as 'Does Spring have support/implementations for all the technologies that comprise the Java EE specification?' -
Nope, but it does do what it set out to do and that is simplify development on most Java EE technologies.
That said, the trade-off for this simplification of Java development is that you need to now have significant amount of knowledge (of the Spring Framework) at your fingertips... (comes with practice and google :) )
>Can't we use Spring for distributed java applications?
Sure you can. Spring has a whole lot of Exporters/FactoryBeans and Clients(Templates) for most conceivable use cases.
Yes Spring can be used in a distributed application without Java EE. We have used it to send messages to MQ and update a database both within one XA transactions.
According to this article, Spring can definitely be used on its own in a distributed application.
http://www.wrox.com/WileyCDA/Section/Why-Use-the-Spring-Framework-.id-130098.html
http://www.artima.com/forums/flat.jsp?forum=276&thread=204508
Historically, (5 years ago?) Spring was weak in the distributed applications area, in particular database clustering. That is no longer a concern. I would say that Spring is going even further for distributed computing these days as they are vigorously pursuing cloud technologies which Java EE hasn't approached yet.
In my view the main benefit of Spring was that it did away with some of the more heavyweight components of the Java EE framework (Entity Beans, session beans) and replacing them with a lightweight alternative.
On of the main benefits of Spring as I see it, is that it decouples a lot of components and then uses XML or Annotations of wiring them together. That makes it easy to write Unit Tests (by injecting mock components instead of real ones), which wasn't something easily done when using heavyweight Java EE components (couldn't easily unit test EJB 2.1 Entity Beans).
A lot of Spring concepts have since gone into the Java EE standards, so I would argue that Java EE is no longer a heavyweight option, and Spring works will with Java EE components such as application server managed connection pools (via JNDI), transaction managers, queue managers that can very easily be managed using an application server which can provide additional functionality such as clustering, failover, load-balancing, serving web resources...
Having said that, the people behind Spring (VMWare) have their own application server (tcServer) which is based on Apache Tomcat and provides a lot of the glue used by spring, but is not considered as "heavy" as some of the traditional Application servers (Websphere, Weblogic).
I don't think so. Basically Spring is about integration between Java EE frameworks.
Use spring inegration framwork for this .
Use can uss Akka framwork for managing distributed applications with spring integration .
Akka uses the Actor Model together with Software Transactional Memory to raise the abstraction level and provide a better platform to build correct concurrent and scalable applications.
Take a look at the step by step tutorial that gives more information about how to build a distributed application using Akka framework.
In general, distributed applications are built in Java using Java-RMI that internally uses Java's inbuilt serialization to pass the objects between the nodes.

What is the best approach to use Vaadin for web application development?

I am just about to create a new Web application (kind of CRM system) with lot of tables, statistics, graphs, etc... and I've decided to do the web interface with Vaadin. Most of the data will come from external Web Services (almost 100 %). My Question is, what would be the best approach to go with? Just to implement pure Vaadin application and some classes to handle the SOAP calls and fill the Vaadin components with the data, or to go with some additional framework e.g. Spring, Struts, etc... and integrate vaading for the UI? Any additional hints would be great.
Thanks
Filip
Using spring is good for dependency injection, security (depending on the sections you are using) but struts and vaadin are web frameworks so mixing them does no sense. You either use struts or vaadin or spring-mvc or any other web framework.
Your question is not really clear but I would say you can use spring rest api to pull data from other web services if they are restful services.

MVC or Rest or Both

I in the process of designing the server side of a web-based user interface that will be very JavaScript intensive.
I originally thought of going with an MVC solution, but now I am thinking I want to use a REST-based solution such as Jersey or Restlets.
Is this often an one or the other type decision or can they be a combined solution?
Thanks,
Mike
MVC is about how the inner side of your app works.
REST is about how your app "talks" with other apps.
You can combine them.
A lot of modern frameworks actually are MVC based and make implementing REST web services easy: Ruby on Rails, Java Spring Framework with SpringMVC , Django, Backbone.js
One of the best Java frameworks I've seen for building MVC webapps with the ability to support REST is SpringMVC. This blog post outlines the REST capabilities in SpringMVC since version 3.0. I've developed REST services using SpringMVC and Jersey, and they are fairly comparable.
They are patterns / solutions to solve different problems.
REST sanitises & simplifies addressing access to features of a web application, for users, client software, etc.
MVC provides a means to organise your application code, making it easier to maintain.
MVC is an architectural design pattern for the layers of your application.
The folder structure:
Models/YourClassModel.php
Views/Home/HomeView.php
Controllers/Controller.php
index.php
The application style REST is the Representational State Transfer of the application.

Categories

Resources