Make ServerProperties bean conditional on being a webapp

This commit is contained in:
Dave Syer 2014-08-20 09:07:41 +01:00
parent f8477bd60e
commit a702ff5c36
2 changed files with 7 additions and 3 deletions

View File

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

View File

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