Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implement the business logic in an app server with spring

Is posible implement the business logic in an App Server remote using pojos instead of either EJB or Servlets???. The main idea is apply a model of 3 layers where the clients may be both web browsers and desktop applications, and they share the business logic in an App Server.

this would be the architecture

browser----- >Web Server -------->|App Server(Business Logic common)|------->|RDBMS common|
desktop App(Swing for example)->|App Server(Business Logic common)|------->|RDBMS common|

like image 889
HenryOS Avatar asked May 24 '10 14:05

HenryOS


People also ask

Which contains the business logic of an application in spring?

The business logic is performed in the Service layer. The spring boot performs all the logic over the data of the database which is mapped to the spring boot model class through Java Persistence Library(JPA).

What is business logic in application server?

Business logic is the custom rules or algorithms that handle the exchange of information between a database and user interface. Business logic is essentially the part of a computer program that contains the information (in the form of business rules) that defines or constrains how a business operates.

Where do we write business logic in spring MVC?

Generally, your business logic goes in the service layer. Though you can put basic validation rules in your pojos with JSR annotations. For a Spring MVC app you have controllers, which handle http requests, and a domain layer, which are pojos representing your business models.


1 Answers

You can use Spring instead of EJBs. And I recommend it!

But both alternatives will handle enterprise features such as transaction handling and security for you in an excellent way.

Using Spring or not, you still need a Servlet container for your web pages. The Servlet container can start the Spring container if you configure the Servlet container's web.xml file correct.

A transaction handling example with Spring:

@Transactional
public void execute(..) {..}

And with EJB 3.x:

@TransactionAttribute
public void execute(..) {..}

As you see, both alternatives offers you to add enterprise features declaratively.

Updated after reading HenryOS's comment:

It's possible to have all the business logic on one server.

One solution can be to use Web Services between the clients (WEB server and the fat Swing clients). It's a quite nice and loosely coupled solution.

If you need more speed, you can consider using Google's Protocol Buffer or similar technology instead.

An interesting thing is that with Web Services or Protocol Buffer, you still need a web container like Tomcat or Jetty on the server with business logic, since it must provide the web services for the clients. All Web Services frameworks like Spring WS, CXF and Apache Axis 2 uses a Servlet.

When it comes to layers, I will recommend two layers on the WEB server, since you only present and retrieve data before sending it to the business server. On the business server I will recommend three layers. The top layer to handle Web Services, business layer in the middle and an integration layer against the database and other enterprise systems at the bottom.

Finally, if you're using CXF or Spring WS together with JAXB, then all your classes on the business server can be written as POJOs! It applies to several other well written Web Service frameworks as well.

I hope this answers your question!

like image 196
Espen Avatar answered Sep 24 '22 19:09

Espen