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
- <properties>
- <tomcat.version>8.0</tomcat.version>
- </properties>
If you want to change server, from tomcat to jetty server the add below code
- <dependencies>
- <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>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
exclude tomcat, and add new dependency w.r.t jetty server.
if you want to change port, then add below code in application.properties
- 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.
- give a result as war file from pom.xml
- deploy the war in webapps of another server.
If you want to deploy your application on application server like Jboss====
Just change pom.xml
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>1.2.7.RELEASE</version>
- </parent>
- <dependencies>
- <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>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- <version>2.5</version>
- <scope>provided</scope>
- </dependency>
- </dependencies>
- <build>
- <finalName>SpringBootBasic</finalName>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
- </project>
and make sure, your SpringApplicationExample.java extends SpringBootServletIntializer
- package younus.attari;
- import org.springframework.boot.SpringApplication;
- import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
- import org.springframework.boot.autoconfigure.SpringBootApplication;
- import org.springframework.boot.builder.SpringApplicationBuilder;
- import org.springframework.boot.context.web.SpringBootServletInitializer;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.annotation.ComponentScan;
- @SpringBootApplication
- @ComponentScan("younus.attari")
- @EnableAutoConfiguration
- public class SpringApplicationExample extends SpringBootServletInitializer {
- public static void main(String[] args) {
- SpringApplication.run(applicationClass, args);
- }
- @Override
- protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
- return application.sources(applicationClass);
- }
- private static Class<SpringApplicationExample> applicationClass = SpringApplicationExample.class;
- }
Source:
Spring boot mongodb configuration