gpt4 book ai didi

java - Spring Boot 2 - AJP

转载 作者:行者123 更新时间:2023-12-02 08:26:31 26 4
gpt4 key购买 nike

我向我的 Spring Boot 2 项目添加了 AJP 连接器

 @Bean
public ServletWebServerFactory 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(redirectConnector());

return tomcat;
}

private Connector redirectConnector() {
Connector connector = new Connector("AJP/1.3");
connector.setScheme("http");
connector.setPort(ajpPort);
connector.setSecure(false);
connector.setAllowTrace(false);
return connector;
}

这很好用。我现在可以通过我的 apache 网络服务器访问我的 spring boot 应用程序。但现在如果我运行我的 Spring Boot 应用程序,我无法直接访问我的 Spring Boot 应用程序。所以这个网址不再有效

http://localhost:13080/online/showlogin?m=test

如果我禁用 AJP 连接器,URL 会再次工作。我尝试过以下方法

 private Connector redirectConnector2() {
Connector connector = new Connector(TomcatServletWebServerFactory.DEFAULT_PROTOCOL);
connector.setScheme("http");
connector.setPort(13080);
connector.setSecure(false);
connector.setAllowTrace(false);
return connector;
}
...
tomcat.addAdditionalTomcatConnectors(redirectConnector2());
...

但这对我没有帮助。

最佳答案

这对我有用:

    @Bean
public WebServerFactoryCustomizer<TomcatServletWebServerFactory> servletContainer() {
return server -> {
if (server instanceof TomcatServletWebServerFactory) {
((TomcatServletWebServerFactory) server).addAdditionalTomcatConnectors(redirectConnector());
}
};
}

private Connector redirectConnector() {
Connector connector = new Connector("AJP/1.3");
connector.setScheme("http");
connector.setPort(ajpPort);
connector.setSecure(false);
connector.setAllowTrace(false);
return connector;
}

关于java - Spring Boot 2 - AJP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49275241/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com