Spring as standalone or on Tomcat?

I am looking for the benefits of using Spring deployed to Tomcat and then to its side on the side of any application server container.

My project does not require any online support. This requires technologies such as transaction management, database pool, JMX, low latency and more common java-ee technology.

So why will I use tomcat? if it is simply because I have DB POOL, I could implement it myself. I am looking for a low latency solution.

Again, my project is a complete backend that does not need any support on the Internet.

So what am I missing here?

+4
source share
5 answers

What do you really mean by "more common Java EE technology"?

If it's “just the back end,” what is the front end? How will apps talk to the back end?

If there is no need for a web interface, there is no advantage to using a web container.

If you have complex transaction management tasks, you need message queues, etc., which can be easier to configure under the application server (as opposed to a web container), since there are existing admin / management interfaces. All of them can be created by themselves, but can be more painful - using Spring can alleviate this pain a little.

However, the need for "more common Java EE technology" makes me a little nervous about implementing a standalone application. Application containers have everything that “regular Java EE technology” is built-in, tested, and functional. If you put a lot of packages together to give you “common Java EE technology” without using a regular Java EE application container, it's likely just to use an application container, which also gives you the advantage of providing normal access to your services from different sources.
+2
source

If your application is not a web application, you can use any application contexts other than the websites listed in the All known implementation classes section. Then you can initiate the context from the main method in the runnable jar.

+1
source

If you do not need online support, you do not need to use tomcat or any other application server. Spring will provide you with most of the features you need. There are many options available for the connection pool, such as c3p0 and apache dbcp. You can use one of them.

The only thing you need to worry about is the clean completion of the process. You can do this by doing your own shutdown.

+1
source

One of the reasons for deploying your application on tomcat is that it will provide you with all the burden of connecting, managing threads, and so on. Nothing that you could implement yourself. But keep in mind that tomcat is reliable and they are already dealing with all the problems of implementing this logic.

In addition, it makes little sense to use the application container (if you think that you do not need to develop and maintain this code).

0
source

You should not use tomcat or anything else. Spring is already a container. Init Spring in one simple thread, make sure it has the correct cleanup thread. and that’s it. I worked on several server-side integration applications that allocate, exchange data through other protocols to another server, and everything was easily done using Web Containers or J2ee Application Servers. Almost everything supports Spring, sometimes with 3d party libs (caching, transactions, pools, etc.). A simplified version might be:

 ... pubcic static void main (String args[]){ Server.server = new Server(...); server.initSpringContext() server.keepAlive(); server.cleanupResources(); } .. abstract class Server{ abstract void initSpring(); abstract void cleanUpResources(); abstract void shutdown(){ this.state = STOP; }; public void keepAlive() while(state!=STOP){ sleep(1000) } } 
0
source

All Articles