[英]Not able to connect spring boot application with SQL SERVER Database
[英]Spring Boot SSL Configured, Server up but not able to connect to Port
我嘗試過使用最新版本的啟動應用程序,想讓其余的 api ssl 安全,我在下面做了創建密鑰庫並放入項目類路徑,服務器啟動,啟動沒有問題,但無法發送請求 8080 或 8443 , 下面是配置,
server.ssl.key-store=KeyStore.p12 server.ssl.key-store-password=shashank server.ssl.key-alias=mydomain server.ssl.key-password=shashank
@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(getHttpConnector()); return tomcat; } private Connector getHttpConnector() { Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); connector.setScheme("https"); connector.setPort(8080); connector.setSecure(true); connector.setRedirectPort(8443); }
信息 84898 --- [主要] osbwembedded.tomcat.TomcatWebServer : Tomcat 在端口上啟動:在此處輸入圖像描述8443 (https) 8080 (https) 和上下文路徑“/事件處理”
由於這是自簽名證書,因此顯示“此證書未從第三方驗證”
嘗試這些更改:
修改application.properties
以將server.ssl.key-store
參數值從KeyStore.p12
編輯為keystore.p12
server.ssl.key-store: keystore.p12
將 TomcatEmbeddedServletContainerFactory bean 添加到@Configuration 類(任何一個)。
@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
@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(initiateHttpConnector());
return tomcat;
}
private Connector initiateHttpConnector() {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setScheme("http");
connector.setPort(8080);
connector.setSecure(false);
connector.setRedirectPort(8443);
return connector;
}
我使用自簽名證書遇到了這個問題,並通過在服務器計算機而不是我的本地計算機中創建證書來解決它,因此您應該運行在服務器計算機中創建證書的 keytool 命令並使用 .p12 生成的文件您的項目和一切都會按預期進行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.