Spring Boot modify tomcat port

Ref: https://blog.csdn.net/wsh900221/article/details/80521313

In spring boot web project, you can use the built-in web container, sometimes need to modify the service port.

Method a: through the configuration and type annotation @Configuration

import org.springframework.beans.factory.annotation.Value;  
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;  
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;  
import org.springframework.context.annotation.Bean;  
import org.springframework.context.annotation.Configuration;  

@Configuration  
public class MyConfiguration {  

    @Value("${tomcatport:8090}")  
    private int port;  

    @Bean  
    public EmbeddedServletContainerFactory servletContainer(){  
        return new TomcatEmbeddedServletContainerFactory(this.port);  
    }  
}

Use @Value comment for tomcatport given port 8090.
Access to treatment TomcatEmbeddedServletContainerFactory like to see implemented.

Method 2: Application of application.properties or yml configuration file, add configuration items

#指定web 的 context path
server.contextPath=/myapp
#指定服务端口
server.port=8080

Guess you like

Origin blog.csdn.net/baidu_25104885/article/details/90448532