Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 298 Vote(s) - 3.42 Average
  • 1
  • 2
  • 3
  • 4
  • 5
spring-boot-starter-tomcat vs spring-boot-starter-web

#1
I'm trying to learn Spring boot and I notice there are two options.

1. spring-boot-starter-web - which according to the docs gives support for full-stack web development, including Tomcat and web-mvc

2. spring-boot-starter-tomcat

Since #1 supports Tomcat why would one want to use #2?

What are the differences?

Thanks
Reply

#2
Well a simple answer is that not all web applications are SpringMVC applications. For example if you wish to use JaxRS instead perhaps you have client applications that use RestTemplate and you like how they interact it doesn't mean you can't use spring boot or embedded tomcat

Here is an example application that uses `spring-boot-starter-tomcat` but not `spring-boot-starter-web`

Simple Jersey application in spring boot using `spring-boot-starter-tomcat`
>https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-jersey

It's also important to remember that tomcat is not the only option for an embedded servlet container in spring boot. It's also easy to get started using jetty. And having `spring-boot-starter-tomcat` makes it easy to exclude all as one module while if they were all just part of spring-web it would be more work to exclude the tomcat libraries to bring in `spring-boot-starter-jersey` instead

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>

I copied this code from another SO question here.

>https://stackoverflow.com/questions/20454441/how-to-configure-jetty-in-spring-boot-easily
Reply

#3


> Since #1 supports Tomcat why would one want to use #2?

`spring-boot-starter-web` contains `spring-boot-starter-tomcat`. `spring-boot-starter-tomcat` could potentially be used on its own if spring mvc isn't needed (contained in `spring-boot-starter-web`).

Here is the dependency hierarchy of `spring-boot-starter-web`:

[![enter image description here][1]][1]

> What are the differences?

`spring-boot-starter-web` contains spring web dependencies (including `spring-boot-starter-tomcat`):

`spring-boot-starter`
`jackson`
`spring-core`
`spring-mvc`
`spring-boot-starter-tomcat`

`spring-boot-starter-tomcat` contains everything related to an embdedded tomcat server:

`core`
`el`
`logging`
`websocket`


What if you want to use spring mvc without the embedded tomcat server?

Just exclude it from the dependency:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>



[1]:

Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through