tomcat使用https协议使用指定端口是8081 Spring Security 会自动变为8443 具体设置方法
时间: 2024-03-10 14:48:29 浏览: 22
如果您已经按照前面的步骤,将 Tomcat 配置为使用 HTTPS 协议,并指定端口号为 8081,那么您需要在 Spring Security 中进行如下配置:
1. 在 Spring Security 的配置文件中,将端口号设置为 8081:
```
server:
port: 8081
ssl:
key-store: classpath:keystore.p12
key-store-password: your_keystore_password
key-store-type: PKCS12
key-alias: tomcat
enabled: true
```
在上面的配置中,我们将端口号设置为 8081,使用的 SSL 证书为 keystore.p12,证书密码为 your_keystore_password,证书类型为 PKCS12,证书别名为 tomcat,启用 HTTPS 协议。
2. 在 WebSecurityConfigurerAdapter 中启用 HTTPS 支持:
```
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.requiresChannel()
.anyRequest().requiresSecure()
.and()
// other security configurations
// ...
}
}
```
在上面的配置中,我们启用了 HTTPS 支持,并要求所有请求都必须使用 HTTPS 协议。
3. 在浏览器中访问应用程序:
现在,您可以在浏览器中访问应用程序,例如 https://localhost:8081。如果一切配置正确,应该能够正常访问应用程序,而且浏览器的地址栏中应该显示 https://localhost:8081。