Spring Apache Tomcat

broken image


Spring.datasource.type = org.apache.tomcat.jdbc.pool.DataSource If we are using Spring Boot 1.x versions, Spring Boot selects Tomcat datasource by default and we need not to configure above line. Now to configure Tomcat specific connection pool settings, Spring Boot provides spring.datasource.tomcat. prefix to be used in application.properties. Spring DataSource. We know that DataSource with JNDI is the preferred way to achieve connection pooling and get benefits of container implementations. Today we will look how we can configure a Spring Web Application to use JNDI connections provided by Tomcat.

Welcome to Spring Boot (With Embedded Tomcat Features) Spring Boot, Maven, and Tomcat can form a powerful alliance. This sample web app shows the interplay between them and how you can easily. How Tomcat classpath usage differs from standard usage. Everything about Apache Tomcat aims to be as self-contained, intuitive, and automatic as possible, in an effort to standardize the configuration and deployment of web applications for efficient administration, while limiting access to different libraries for security and namespace reasons.

How to Setup Apache as Reverse Proxy for Tomcat Server using mod proxy - 2020




bogotobogo.com site search:

Assuming we already have installed Apache Httpd and Apache Tomcat, and running them on a Debian/Ubuntu compatible machine.

Spring Boot Apache Tomcat Native Library

Apache server on the same host running on port 80. We'll use Apache server to get users requests and forward these requests to corresponding applications running on back-end Tomcat server on port 8080.

So, we need to configure Apache to transfer requests to tomcat.

Though there are several ways to do this, in this tutorial, we are going to use mod_proxy which is a general propose proxy module. This can be used to forward requests for a particular web application to a Tomcat instance, without having to configure a web connector such as mod_jk.

The main idea is to setup a VirtualHost exclusive for tomcat on a given path of our site.



Here is the /var/lib/tomcat8/webapps file structure. Under it we have our Spring Boot app (Spring Boot : Deploying War file to Tomcat 8's webapps) folder, gs-spring-boot-0.1.0:


We want to access home page of the app by http://tomcat.example.com:80. But Tomcat server, by default, listens to 8080, and that's why we want to use proxy setup for Apache.

In our local machine we've already setup the domain via /etc/hosts file:

Apache

Enable mod_proxy

You need to enable 2 modules: proxy and proxy_http using a2enmod command:


Here is the Apache VirtualHost configuration, /etc/apache2/sites-available/tomcat.example.com:

The key lines are ProxyPass*:

At the '/' request, the traffics are forwarded to http://localhost:8080//gs-spring-boot-0.1.0/ via port 8080 which Tomcat is listening to. Note also it goes to gs-spring-boot-0.1.0 which is the our app name (app.war).

Then, we need to make a link for sites-enables:

After enabling the site, we can check if it's really setup:

To disable it:

Let's restart the server:


Test

As we can see from the picture below, we're now able to access via our domain name (tomcat.example.com) with port 80:


To access Tomcat home, we can still use localhost:8080:


It looked like the Proxy setup was complete but later I found there was an issue of keeping the session id. It appears whenever we proxied, a new session is created, so page navigation starts to break.

After a couple of tries, I came up with a solution though not perfect. The url has to have domain/x, and here is my configuration for the proxy on Apache:

The redirect from '/' to '/x' is a side-effect of my solution. Otherwise, it goes to tomcat manager page but not to my root page.


Here is my site deployed on my VPS:


Please let me know if you know how to remove the x in the url.


The source is available from spring-mvc-showcase.


Please enable JavaScript to view the comments powered by Disqus.

First of all the wording 'JBoss' is improper. There is not anymore a single product called 'JBoss', but just a unit of Red Hat with that name which develops middleware products. (Check this to learn more: What is JBoss ?) I assume you are referring to 'WildFly' application server that is the new name for the Community version of the application server developed by Red Hat Team.

WildFly vs Tomcat: the basics

The difference between WildFly and Tomcat is pretty straightforward: WildFly is a full Java EE application Server, while Tomcat is a Java servlet container and web server and, since because it doesn't come with an implementation of the full JEE stack, it is lighter out of the box. So in a nutshell, if you are designing a Java EE application that uses Servlets/JSP stuff you can run it both on WildFly and Tomcat. If you are using additional Java EE components like EJB, CDI, Transaction Manager etc. then you need an application server like WildFly.

Spring

WildFly vs Tomcat: a modern view

Cleared the basics, today when we compare WildFly with Tomcat we often mean to compare Java EE with Spring. Why ? in today's projects, almost none (except very small projects) rely just on JSP or Servlets. Even if you just need the Web stack, a framework is needed on the top of it to organize most common aspects like Models, Controllers and Views. So we have to add something on the top of Tomcat to be more productive, resilient, reliable etc.

The natural choice if you don't embrace the Java EE standard is to use Spring, or the configuration-less version of it Spring Boot.

The comparison between Spring/Spring Boot and Java EE application servers like WildFly is often based on assumptions that just don't fit it in any more. For example, the most common myth is that Java EE application servers are heavyweight and Spring is a lighter platform.

That just doesn't make sense any more: as a matter of fact today application servers are also extremely fast and light. They switched from those monolythic architectures to very light, modular arhitectures. For example Wildfly features several profiles, each one using a different set of subsystems and modules: there is a default profile for non-clustered an non-JMS applications, one 'full' profile which includes also JMS and Corba, an 'HA' profile that adds clustering on the top of the 'default' and a 'full-ha' that delivers the full Java EE stack in clustered mode. In the recent version of the application server also a 'load balancer' profile has been added so that WildFly can also be used as a front-end load balancer (similar to an Apache Web Server) to a back-end cluster. If that is not enough, you can still trim the application server, choosing which modules you want to use and which not, provided that you respect the dependencies of each module.

The real comparison between WildFly and Spring is done on other aspects.

JEE application servers are an effort for standardization. It takes what is done, or doable by most java enterprise software providers and sticks it into a document. This allows for a very nice portability situation, but in order to do that, it still must rely on the common denominator.

Spring, on the other hand, doesn't have to do that. It is free to innovate, extend, that's why you have so extremely nice Spring additions for some Big Data solutions, Spring Security and a lot of auto-configuration which enable developers to create projects more rapidly.

There's a very good way of doing microservices in Spring boot although there are now also alternative solutions also in the JEE world, like for example the Thorntail project that lets you assemble a Java EE application in an executable archive. Spring Boot has already started this race well ahead but if you have invested in learning or hiring Java EE developers there is also the opportunity to develop micro services using the Java EE stack.

WildFly vs Tomcat: the Apache Tom EE project

Spring is not the only alternative to expand the default Tomcat installation. Another option is using Apache TomEE which is a Java EE Web Profile-certified stack which is built on top of an Apache Tomcat base integrated with additional related technologies. It adds implementations for the following specifications (using the Apache project shown in parentheses):

  • CDI - Apache OpenWebBeans
  • EJB - Apache OpenEJB
  • JPA - Apache OpenJPA
  • JSF - Apache MyFaces
  • JSP - Apache Tomcat
  • JSTL - Apache Tomcat
  • JTA - Apache Geronimo Transaction
  • Servlet - Apache Tomcat
  • Javamail - Apache Geronimo JavaMail
  • Bean Validation - Apache BVal
  • JAX-RS - Apache CXF
  • JAX-WS - Apache CXF
  • JMS - Apache ActiveMQ
  • Connector - Apache Geronimo Connector

Conclusion

To sum up from the original question 'JBoss vs Tomcat' or better to say 'WildFly vs Tomcat' it boils down mostly to a Spring vs Java EE

What is apache tomcat error

Enable mod_proxy

You need to enable 2 modules: proxy and proxy_http using a2enmod command:


Here is the Apache VirtualHost configuration, /etc/apache2/sites-available/tomcat.example.com:

The key lines are ProxyPass*:

At the '/' request, the traffics are forwarded to http://localhost:8080//gs-spring-boot-0.1.0/ via port 8080 which Tomcat is listening to. Note also it goes to gs-spring-boot-0.1.0 which is the our app name (app.war).

Then, we need to make a link for sites-enables:

After enabling the site, we can check if it's really setup:

To disable it:

Let's restart the server:


Test

As we can see from the picture below, we're now able to access via our domain name (tomcat.example.com) with port 80:


To access Tomcat home, we can still use localhost:8080:


It looked like the Proxy setup was complete but later I found there was an issue of keeping the session id. It appears whenever we proxied, a new session is created, so page navigation starts to break.

After a couple of tries, I came up with a solution though not perfect. The url has to have domain/x, and here is my configuration for the proxy on Apache:

The redirect from '/' to '/x' is a side-effect of my solution. Otherwise, it goes to tomcat manager page but not to my root page.


Here is my site deployed on my VPS:


Please let me know if you know how to remove the x in the url.


The source is available from spring-mvc-showcase.


Please enable JavaScript to view the comments powered by Disqus.

First of all the wording 'JBoss' is improper. There is not anymore a single product called 'JBoss', but just a unit of Red Hat with that name which develops middleware products. (Check this to learn more: What is JBoss ?) I assume you are referring to 'WildFly' application server that is the new name for the Community version of the application server developed by Red Hat Team.

WildFly vs Tomcat: the basics

The difference between WildFly and Tomcat is pretty straightforward: WildFly is a full Java EE application Server, while Tomcat is a Java servlet container and web server and, since because it doesn't come with an implementation of the full JEE stack, it is lighter out of the box. So in a nutshell, if you are designing a Java EE application that uses Servlets/JSP stuff you can run it both on WildFly and Tomcat. If you are using additional Java EE components like EJB, CDI, Transaction Manager etc. then you need an application server like WildFly.

WildFly vs Tomcat: a modern view

Cleared the basics, today when we compare WildFly with Tomcat we often mean to compare Java EE with Spring. Why ? in today's projects, almost none (except very small projects) rely just on JSP or Servlets. Even if you just need the Web stack, a framework is needed on the top of it to organize most common aspects like Models, Controllers and Views. So we have to add something on the top of Tomcat to be more productive, resilient, reliable etc.

The natural choice if you don't embrace the Java EE standard is to use Spring, or the configuration-less version of it Spring Boot.

The comparison between Spring/Spring Boot and Java EE application servers like WildFly is often based on assumptions that just don't fit it in any more. For example, the most common myth is that Java EE application servers are heavyweight and Spring is a lighter platform.

That just doesn't make sense any more: as a matter of fact today application servers are also extremely fast and light. They switched from those monolythic architectures to very light, modular arhitectures. For example Wildfly features several profiles, each one using a different set of subsystems and modules: there is a default profile for non-clustered an non-JMS applications, one 'full' profile which includes also JMS and Corba, an 'HA' profile that adds clustering on the top of the 'default' and a 'full-ha' that delivers the full Java EE stack in clustered mode. In the recent version of the application server also a 'load balancer' profile has been added so that WildFly can also be used as a front-end load balancer (similar to an Apache Web Server) to a back-end cluster. If that is not enough, you can still trim the application server, choosing which modules you want to use and which not, provided that you respect the dependencies of each module.

The real comparison between WildFly and Spring is done on other aspects.

JEE application servers are an effort for standardization. It takes what is done, or doable by most java enterprise software providers and sticks it into a document. This allows for a very nice portability situation, but in order to do that, it still must rely on the common denominator.

Spring, on the other hand, doesn't have to do that. It is free to innovate, extend, that's why you have so extremely nice Spring additions for some Big Data solutions, Spring Security and a lot of auto-configuration which enable developers to create projects more rapidly.

There's a very good way of doing microservices in Spring boot although there are now also alternative solutions also in the JEE world, like for example the Thorntail project that lets you assemble a Java EE application in an executable archive. Spring Boot has already started this race well ahead but if you have invested in learning or hiring Java EE developers there is also the opportunity to develop micro services using the Java EE stack.

WildFly vs Tomcat: the Apache Tom EE project

Spring is not the only alternative to expand the default Tomcat installation. Another option is using Apache TomEE which is a Java EE Web Profile-certified stack which is built on top of an Apache Tomcat base integrated with additional related technologies. It adds implementations for the following specifications (using the Apache project shown in parentheses):

  • CDI - Apache OpenWebBeans
  • EJB - Apache OpenEJB
  • JPA - Apache OpenJPA
  • JSF - Apache MyFaces
  • JSP - Apache Tomcat
  • JSTL - Apache Tomcat
  • JTA - Apache Geronimo Transaction
  • Servlet - Apache Tomcat
  • Javamail - Apache Geronimo JavaMail
  • Bean Validation - Apache BVal
  • JAX-RS - Apache CXF
  • JAX-WS - Apache CXF
  • JMS - Apache ActiveMQ
  • Connector - Apache Geronimo Connector

Conclusion

To sum up from the original question 'JBoss vs Tomcat' or better to say 'WildFly vs Tomcat' it boils down mostly to a Spring vs Java EE

Java EE Pros:

1. Relies on standard specifications which guarantees stability in your projects.

2. Has a robust set of management interface to admin the application server

3. Is a robust solution which provides out of the box load balancing and high availability

Apache Tomcat Rpm

Spring/Spring Boot Pros:

1. Provides since the beginning innovative concepts like Inversion Of Control / Dependency Injection and (Spring Boot) auto-configuration with sensible defaults

2. Provides a powerful CLI to bootstrap projects

3. Provides (Spring Boot) an already well popular solution for developing microservices

You can get learning more about Spring Boot in our new site that contains lots of Spring Boot tutorials.





broken image