Notice
Link
- Today
- Total
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- reactnative
- sql exception
- CSS
- 말줌임 CSS
- kill -9
- group by
- CentOS
- 가변영역 스크롤
- 코드로 서버 재실행
- springboot 재가동
- Activity 전체화면
- mybatis exception
- springboot
- MariaDB
- 시간대 테이블생성
- pid 찾아 kill
- MFC
- 피쉬랜드
- ffmpeg
- MySQL
- 시간대별 통계
- vc++
- rn
- 파티션 빠른 삭제
- 스크롤적용
- SQL
- 터치좌표 view
- Back 키 클릭 감지
- view 획득
- c언어
Archives
개발은 하는건가..
[Springboot] http 접속 시 https 로 자동 전환 시키기 본문
반응형
http 로 접속 시 https 로 리다이렉트 시키기 위해 다음과 같이 webConfig 클래스를 추가 하고 bean 을 등록한다.
@Configuration
public class WebConfig {
@Bean
public TomcatServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
@Override
protected void postProcessContext(Context context) {
SecurityConstraint securityConstraint = new SecurityConstraint();
securityConstraint.setUserConstraint("CONFIDENTIAL");
SecurityCollection collection = new SecurityCollection();
collection.addPattern("/*");
securityConstraint.addCollection(collection);
context.addConstraint(securityConstraint);
}
};
tomcat.addAdditionalTomcatConnectors(createHttpConnector());
return tomcat;
}
private Connector createHttpConnector() {
Connector connector = new Connector(TomcatServletWebServerFactory.DEFAULT_PROTOCOL);
connector.setScheme("http");
connector.setPort(80); // http 로 받는 포트
connector.setSecure(false);
connector.setRedirectPort(443); // https 로 전환시 사용하는 포트
return connector;
}
}
문제는 동일 포트로 접속 시 http 를 https 로 바뀌게 하는건 안되는 것이 방법을 모르겠음.
http 와 https 포트를 다르게 bind 했을 때만 동작을 함.
'SpringBoot , Thymeleaf' 카테고리의 다른 글
[springboot] RestTemplate 를 이용한 간단하게 http 요청 (1) | 2024.01.03 |
---|---|
[mybatis] Sql Exception 처리 (0) | 2023.09.12 |
[Springboot] 서버 재가동 RestAPI 코드 작성 (0) | 2023.08.25 |
[lo4j2] 로그 파일로 생성되게 하기 (2) | 2023.06.09 |
mybatis DTO 클래스 aliasesPackage 지정 (0) | 2023.05.25 |
Comments