Spring Boot Framework
[Spring Boot] Embedded Server Port 변경
헤르메스의날개
2023. 1. 29. 10:27
728x90
내장 Tomcat 의 Port 번호를 변경하는 방법 여러가지 입니다.
정리 해 둡니다.
1, 설정파일 변경 ( 가장 쉬움 )
application.properties
#Server port
server.port=8081
application.yml
#Server port
server:
port: 9091
2, 프로그램 환경 설정
2-1. DefaultProperties 설정
package simple.spring;
import java.util.Collections;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
public class AppSpringBootApplication {
public static void main(String[] args) {
// SpringApplication.run(AppSpringBootApplication.class, args);
SpringApplication app = new SpringApplication(AppSpringBootApplication.class);
app.setDefaultProperties(Collections.singletonMap("server.port", "9091"));
app.run(args);
}
}
2-2. WebServerFactoryCustomizer 설정
package simple.spring;
import org.springframework.boot.web.server.ConfigurableWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.stereotype.Component;
@Component
public class ServletConfig implements WebServerFactoryCustomizer<ConfigurableWebServerFactory> {
@Override
public void customize(ConfigurableWebServerFactory factory) {
factory.setPort(9091);
}
}
3, 명령 줄 설정
java -jar spring-5.jar --server.port=8083
java -jar -Dserver.port=8083 spring-5.jar
4. 임베디드 서버 설정
설정 적용 순서
1. 임베디드 서버 설정
2. 명령 줄 설정
3. 설정파일
4. 프로그램 환경
https://www.baeldung.com/spring-boot-change-port
728x90