반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- ArrayList
- javascript
- Files
- date
- Button
- CSS
- list
- 배열
- Java
- string
- 이탈리아
- 자바
- 테이블
- Array
- json
- html
- IntelliJ
- 인텔리제이
- js
- input
- windows
- 문자열
- 이클립스
- vscode
- Eclipse
- table
- CMD
- Maven
- 자바스크립트
- Visual Studio Code
Archives
- Today
- Total
어제 오늘 내일
[Spring Boot] 서버 포트 변경하기 본문
- application.properties 파일 수정하기
- Command Line 옵션 추가하기
- WebServerFactoryCustomizer 인터페이스 구현하기
- SpringApplication의 setDefaultProperties
1. application.properties 파일 수정하기
server.port = 8081
2. Command Line 옵션 추가하기
java -jar hello-spring.jar --server.port=8081
또는
java -jar -Dserver.port=8081 hello-spring.jar
3. WebServerFactoryCustomizer 인터페이스 구현하기
@Component
public class MyWebServerFactoryCustomizer implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {
@Override
public void customize(ConfigurableServletWebServerFactory server) {
server.setPort(7777);
}
}
프로그램으로 servlet container 정보를 설정하기 위해서는,
WebServerFactoryCustomizer 인터페이스를 bean으로 등록해야 합니다.
이, WebServerFactoryCustomizer를 통해서 ConfigurableServletWebServerFactory에 접근할 수 있고,
이를 통해 서버의 포트 번호를 포함한 Servlet Container의 정보를 변경할 수 있습니다.
4. SpringApplication의 setDefaultProperties
@SpringBootApplication
public class HelloSpringApplication {
public static void main(String[] args) {
SpringApplication app = new SpringApplication(HelloSpringApplication.class);
app.setDefaultProperties(Collections.singletonMap("server.port", "8081"));
app.run(args);
}
}
SpringApplication의 setDefaultProperties를 사용하여 port를 변경할 수 있습니다.
반응형
'IT > SpringBoot' 카테고리의 다른 글
[Spring] 등록 된 모든 Bean 목록 출력하기 (1) | 2024.04.08 |
---|---|
[Spring Boot] @RequestParam 어노테이션 사용법 (0) | 2023.12.20 |
[Spring Boot / 에러] Name for argument of type [java.lang.String] not specified, and parameter name information not found in class file either (0) | 2023.12.19 |
[SpringBoot] SpringBoot 특징 (0) | 2021.10.04 |
Comments