在spring boot的web 工程中,可以使用内置的web container、有时需要修改服务端口。
方法一:通过配置类和@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);
}