5858
5959import org .springframework .beans .factory .config .BeanDefinition ;
6060import org .springframework .boot .autoconfigure .AutoConfigurationPackages ;
61- import org .springframework .boot .autoconfigure .web .servlet .error .BasicErrorController ;
6261import org .springframework .context .ApplicationContext ;
6362import org .springframework .context .annotation .ClassPathScanningCandidateComponentProvider ;
6463import org .springframework .core .annotation .AnnotatedElementUtils ;
@@ -167,7 +166,7 @@ public class OpenAPIService {
167166 this .securityParser = securityParser ;
168167 this .springDocConfigProperties = springDocConfigProperties ;
169168 this .openApiBuilderCustomisers = openApiBuilderCustomisers ;
170- if (springDocConfigProperties .isUseFqn ())
169+ if (springDocConfigProperties .isUseFqn ())
171170 TypeNameResolver .std .setUseFqn (true );
172171 }
173172
@@ -223,12 +222,28 @@ else if (calculatedOpenAPI.getInfo() == null) {
223222 }
224223
225224 private void initializeHiddenRestController () {
226- getConfig ().addHiddenRestControllers (BasicErrorController .class );
225+ Class basicErrorController = null ;
226+ try {
227+ //spring-boot 2
228+ basicErrorController = Class .forName ("org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController" );
229+ }
230+ catch (ClassNotFoundException e ) {
231+ //spring-boot 1
232+ try {
233+ basicErrorController = Class .forName ("org.springframework.boot.autoconfigure.web.BasicErrorController" );
234+ }
235+ catch (ClassNotFoundException classNotFoundException ) {
236+ //Basic error controller class not found
237+ LOGGER .warn (classNotFoundException .getMessage ());
238+ }
239+ }
240+ if (basicErrorController != null )
241+ getConfig ().addHiddenRestControllers (basicErrorController );
227242 List <Class <?>> hiddenRestControllers = this .mappingsMap .entrySet ().parallelStream ()
228243 .filter (controller -> (AnnotationUtils .findAnnotation (controller .getValue ().getClass (),
229244 Hidden .class ) != null )).map (controller -> controller .getValue ().getClass ())
230245 .collect (Collectors .toList ());
231- if (!CollectionUtils .isEmpty (hiddenRestControllers ))
246+ if (!CollectionUtils .isEmpty (hiddenRestControllers ))
232247 getConfig ().addHiddenRestControllers (hiddenRestControllers .toArray (new Class <?>[hiddenRestControllers .size ()]));
233248 }
234249
@@ -239,7 +254,7 @@ private void initializeHiddenRestController() {
239254 * @return the open api
240255 */
241256 public OpenAPI updateServers (OpenAPI openAPI ) {
242- if (!isServersPresent && serverBaseUrl != null ) // default server value
257+ if (!isServersPresent && serverBaseUrl != null ) // default server value
243258 {
244259 Server server = new Server ().url (serverBaseUrl ).description (DEFAULT_SERVER_DESCRIPTION );
245260 List <Server > servers = new ArrayList <>();
0 commit comments