Configuring Servers With Spring boot

Consider you are using tomcat, springboot by default uses tomcat 7, if you want to change a version to tomcat 8, please add the below code in pom.xml

  1. <properties>
  2. <tomcat.version>8.0</tomcat.version>
  3. </properties>

If you want to change server, from tomcat to jetty server the add below code

  1. <dependencies>
  2. <dependency>
  3. <groupId>org.springframework.boot</groupId>
  4. <artifactId>spring-boot-starter-web</artifactId>
  5. <exclusions>
  6. <exclusion>
  7. <groupId>org.springframework.boot</groupId>
  8. <artifactId>spring-boot-starter-tomcat</artifactId>
  9. </exclusion>
  10. </exclusions>
  11. </dependency>
  12. <dependency>
  13. <groupId>org.springframework.boot</groupId>
  14. <artifactId>spring-boot-starter-jetty</artifactId>
  15. </dependency>
  16. <dependency>
  17. <groupId>org.springframework.boot</groupId>
  18. <artifactId>spring-boot-starter-test</artifactId>
  19. <scope>test</scope>
  20. </dependency>
  21. </dependencies>

exclude tomcat, and add new dependency w.r.t jetty server.

f:id:saravanagumar:20180808184155j:plain

springbootmongodb

if you want to change port, then add below code in application.properties

  1. server.port=8090

if you give server.port=0, then it will assign unused port number by default.

How to deploy spring-boot in other tomcat server.

  1. give a result as war file from pom.xml
  2. deploy the war in webapps of another server.

If you want to deploy your application on application server like Jboss====
Just change pom.xml

  1. <parent>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-parent</artifactId>
  4. <version>1.2.7.RELEASE</version>
  5. </parent>
  6. <dependencies>
  7. <dependency>
  8. <groupId>org.springframework.boot</groupId>
  9. <artifactId>spring-boot-starter-web</artifactId>
  10. <exclusions>
  11. <exclusion>
  12. <groupId>org.springframework.boot</groupId>
  13. <artifactId>spring-boot-starter-tomcat</artifactId>
  14. </exclusion>
  15. </exclusions>
  16. </dependency>
  17. <dependency>
  18. <groupId>javax.servlet</groupId>
  19. <artifactId>servlet-api</artifactId>
  20. <version>2.5</version>
  21. <scope>provided</scope>
  22. </dependency>
  23. </dependencies>
  24. <build>
  25. <finalName>SpringBootBasic</finalName>
  26. <plugins>
  27. <plugin>
  28. <groupId>org.springframework.boot</groupId>
  29. <artifactId>spring-boot-maven-plugin</artifactId>
  30. </plugin>
  31. </plugins>
  32. </build>
  33. </project>

and make sure, your SpringApplicationExample.java extends SpringBootServletIntializer

  1. package younus.attari;
  2. import org.springframework.boot.SpringApplication;
  3. import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  4. import org.springframework.boot.autoconfigure.SpringBootApplication;
  5. import org.springframework.boot.builder.SpringApplicationBuilder;
  6. import org.springframework.boot.context.web.SpringBootServletInitializer;
  7. import org.springframework.context.ApplicationContext;
  8. import org.springframework.context.annotation.ComponentScan;
  9. @SpringBootApplication
  10. @ComponentScan("younus.attari")
  11. @EnableAutoConfiguration
  12. public class SpringApplicationExample extends SpringBootServletInitializer {
  13. public static void main(String[] args) {
  14. SpringApplication.run(applicationClass, args);
  15. }
  16. @Override
  17. protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
  18. return application.sources(applicationClass);
  19. }
  20. private static Class<SpringApplicationExample> applicationClass = SpringApplicationExample.class;
  21. }

 

Source:

Spring boot mongodb configuration

 

Spring boot official