Make ServerProperties bean conditional on being a webapp

pull/1433/head
Dave Syer 10 years ago
parent a9d0815e0c
commit 171b2e452b

@ -122,7 +122,7 @@ public class ManagementSecurityAutoConfiguration {
@Autowired @Autowired
private SecurityProperties security; private SecurityProperties security;
@Autowired @Autowired(required = false)
private ServerProperties server; private ServerProperties server;
@Override @Override
@ -148,8 +148,10 @@ public class ManagementSecurityAutoConfiguration {
if (this.errorController != null) { if (this.errorController != null) {
ignored.add(normalizePath(this.errorController.getErrorPath())); ignored.add(normalizePath(this.errorController.getErrorPath()));
} }
String[] paths = this.server.getPathsArray(ignored); if (this.server != null) {
ignoring.antMatchers(paths); String[] paths = this.server.getPathsArray(ignored);
ignoring.antMatchers(paths);
}
} }
private String normalizePath(String errorPath) { private String normalizePath(String errorPath) {

@ -20,6 +20,7 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.security.SecurityProperties; import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
@ -55,6 +56,7 @@ public class ManagementServerPropertiesAutoConfiguration {
// In case server auto configuration hasn't been included // In case server auto configuration hasn't been included
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnWebApplication
public ServerProperties serverProperties() { public ServerProperties serverProperties() {
return new ServerProperties(); return new ServerProperties();
} }

@ -316,6 +316,7 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer {
public void customize(Connector connector) { public void customize(Connector connector) {
ProtocolHandler handler = connector.getProtocolHandler(); ProtocolHandler handler = connector.getProtocolHandler();
if (handler instanceof AbstractProtocol) { if (handler instanceof AbstractProtocol) {
@SuppressWarnings("rawtypes")
AbstractProtocol protocol = (AbstractProtocol) handler; AbstractProtocol protocol = (AbstractProtocol) handler;
protocol.setMaxThreads(Tomcat.this.maxThreads); protocol.setMaxThreads(Tomcat.this.maxThreads);
} }
@ -329,6 +330,7 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer {
public void customize(Connector connector) { public void customize(Connector connector) {
ProtocolHandler handler = connector.getProtocolHandler(); ProtocolHandler handler = connector.getProtocolHandler();
if (handler instanceof AbstractHttp11Protocol) { if (handler instanceof AbstractHttp11Protocol) {
@SuppressWarnings("rawtypes")
AbstractHttp11Protocol protocol = (AbstractHttp11Protocol) handler; AbstractHttp11Protocol protocol = (AbstractHttp11Protocol) handler;
protocol.setMaxHttpHeaderSize(Tomcat.this.maxHttpHeaderSize); protocol.setMaxHttpHeaderSize(Tomcat.this.maxHttpHeaderSize);
} }

Loading…
Cancel
Save