Spring boot web app configuration

As we discussed in earlier tutorials that spring boot will take care of all boilerplate code, so it will provide all configurations automatically. But we can change the default configurations.

Spring boot change default tomcat port

Default HTTP port in spring boot application is 8080. We can change it by overriding the default port in the application.properties file.

server.port=7001

Spring boot change context path

Default context path in spring boot application is “/”. We can change it by overriding the default port in the application.properties file.

server.contextPath=/w3spoint

Spring boot configure log level

We can configure the logging levels in the application.properties file.

logging.level.org.springframework.web=DEBUG
logging.level.org.hibernate=ERROR

Shut down a boot application pro-grammatically

We can shut down a boot application programmatically with SpringApplication class. It provides static exit() method which takes two arguments (ApplicationContext and an ExitCodeGenerator).

@Autowired
public void shutDown(ExecutorServiceExitCodeGenerator exitCodeGenerator) {
    SpringApplication.exit(applicationContext, exitCodeGenerator);
}

Spring boot configure jetty

Default embedded server in spring boot application is apache tomcat. We can change it, we are using jetty server here.

<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>
@Bean
public JettyEmbeddedServletContainerFactory  jettyEmbeddedServletContainerFactory() {
    JettyEmbeddedServletContainerFactory jettyContainer = 
      new JettyEmbeddedServletContainerFactory();
 
    jettyContainer.setPort(7001);
    jettyContainer.setContextPath("/springbootapp");
    return jettyContainer;
}
Please follow and like us:
Content Protection by DMCA.com