user2434
user2434

Reputation: 6399

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?

Upvotes: 7

Views: 5971

Answers (7)

Vijay
Vijay

Reputation: 5010

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.

Upvotes: 0

chalimartines
chalimartines

Reputation: 5653

I don't think so. Basically Spring is about integration between Java EE frameworks.

Upvotes: 0

beny23
beny23

Reputation: 35018

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).

Upvotes: 0

Pace
Pace

Reputation: 43817

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.

Upvotes: 0

Prashanth
Prashanth

Reputation: 1398

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

Upvotes: 1

Ryan Fernandes
Ryan Fernandes

Reputation: 8526

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:

  1. POJO -> facilitates easy testing
  2. DI -> promotes loose coupling
  3. AOP -> promotes separation of concerns, maintainability etc
  4. 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.

Upvotes: 2

helios
helios

Reputation: 13841

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.

Upvotes: 3

Related Questions