【发布时间】:2018-08-22 20:02:17
【问题描述】:
我在我的 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());
...
但这对我没有帮助。
【问题讨论】:
-
不是创建
TomcatServletWebServerFactory,而是创建一个WebServerFactoryCustomizer<TomcatServletWebServerFactory>,它添加了AJP的东西。这将在 Spring Boot 的默认配置之外执行。
标签: java spring spring-boot