Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change server in spring boot application?

My project requirement is to use another server than tomcat? How can we change embedded server from spring boot application?

like image 749
Vikram Shekhawat Avatar asked Dec 14 '22 08:12

Vikram Shekhawat


2 Answers

You have to exclude tomcat from starter 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>

and now you need to include new server as a dependency i.e.:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
like image 192
Planck Constant Avatar answered Dec 28 '22 17:12

Planck Constant


You will need to update pom.xml, add the dependency for spring-boot-starter-jetty. Also, you will need to exclude default added spring-boot-starter-tomcat 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>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jetty</artifactId>
</dependency>

In gradle,

configurations {
    compile.exclude module: "spring-boot-starter-tomcat"
}
 
dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("org.springframework.boot:spring-boot-starter-jetty")
}
like image 35
Thirumal Avatar answered Dec 28 '22 18:12

Thirumal