Swagger UI - org.springdoc - throws whitelabel error - spring-boot

To mitigate Log4j vulnerability(2.14 to 2.17), we have migrated from spring boot 2.4.0 to 2.6.4. Since Spring Fox was having some issues we migrated to spring doc.
Swagger UI works fine on local, when moved to server (JBOSS), we get white label error , sometimes it works .
can someone help me on this or best alternative to mitigate the Log4j vulnerability.
Used Below Dependency in pom.xml:
Spring Boot version from 2.4.0 to 2.6.4
<dependency>
<groupId>org.springdoc</groupId>
<artifact>springdoc-openapi-ui</artifact>
<version>1.6.6</version>
</dependency>
application.properties :
application-description=#project.description#
application-version=#project.version#
main class :
#Bean
public OpenAPI Internal_APIs(#Value("${application-description}") String appDesciption, #Value("${application-version}") String appVersion)
{
return new OpenAPI()
.info(new Info()
.title("Internal")
.version(appVersion)
.description(appDesciption)
.license(new License()
.name("Apache 2.0")
.url("http://springdoc.org")))
.externalDocs(new External Documentation()
.url("http://springdoc.org"));
}

Related

404 error on Swagger UI with Spring (springdoc-openapi configuration)

I am adding swagger UI to my Spring boot application. When I try to access the swagger-ui.html. I get the 404 error.
Config class :
#Configuration
public class SwaggerConfig {
#Bean
public OpenAPI springShopOpenAPI() {
return new OpenAPI()
.info(new Info().title("JOYAS-STOCK API Docs")
.description("JOYAS-STOCK REST API documentation")
.version("v1.0.0"));
}
}
appliaction.properties :
#swagger-ui config
springdoc.swagger-ui.path=/swagger-ui
springdoc.swagger-ui.operationsSorter=method
springdoc.swagger-ui.tagsSorter=alpha
pom.xml :
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.13</version>
</dependency>
error message :
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
There was an unexpected error (type=Not Found, status=404).
i started with the implementation of the configuration of swagger
and apparently it's not working.
click to see screen of the error
Resolved.
the issue was in the versions, they were not compatible! i was using springdoc-openapi v1 with spring boot 3.
which is wrong! with spring boot 3, springdoc-openapi v2 should be used.
see documentation : https://springdoc.org/v2/

Swagger UI page is found for Spring Boot 2

Using Spring Boot 2.3.1.
Here is a snippet from pom:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger-version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger-version}</version>
</dependency>
Where swagger version is last for now: 3.0.0.
Swagger configuration:
#Configuration
#EnableSwagger2
public class SwaggerConfiguration {
#Bean
public Docket swaggerApiDocket() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.paths(PathSelectors.any())
.apis(RequestHandlerSelectors.basePackage("com.demo.controller"))
.build()
.apiInfo(apiDetails());
}
private ApiInfo apiDetails() {
return new ApiInfo("Carpark Controller API",
"Carpark Service for managing car parks",
"0.0.1",
"",
new springfox.documentation.service.Contact("Jan",
"www.demo.com",
""),
"API License",
"",
Collections.emptyList());
}
}
No Security configuration is added. No any server-path or some additional configuration.
When the application is up swagger JSON documentation is available:
http://localhost:8080/v2/api-docs
However, if to navigate to swagger UI:
http://localhost:8080/swagger-ui.html
The result will be:
There was an unexpected error (type=Not Found, status=404).
Tried to downgrade swagger version to 2.9.2 result is the same.
How to solve this issue?
Found solution for Spring Boot 2:
Get read from all other swagger dependencies from pom file. Only add next one:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
Swagger configuration could be the same as it was before with #EnableSwagger2.
Start the application.
Swagger UI page is different now:
http://localhost:8080/swagger-ui/index.html
Finally, it works!
Looking for a solution at the web for this issue found the following comment.
Saw the latest samples for Spring Boot version: BootWebmvcApplication
And build.gradle configuration for it.
Here is a link to other projects sources.
In POM.XML file you missed one dependency that has swagger starter
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
</dependency>

Why am I getting this NoClassDefFound error?

I am trying to create a contract in Spring(https://spring.io/projects/spring-cloud-contract)
This is the error I keep getting:
Tests in error: ContractVerifierTest.validate_shouldReturnPreviousAddress:19 ยป NoClassDefFound
And this is the line causing the problem:
// given:
MockMvcRequestSpecification request = given();
This is my groovy file:
package contracts
import org.springframework.cloud.contract.spec.Contract
Contract.make {
request {
method 'GET'
url value(consumer('/echo'), producer('/echo'))
}
response {
status 200
headers {
header(
'Content-Type', value(consumer('text/plain;charset=ISO-8859-1'), producer(regex('text/plain;charset=ISO-8859-1')))
)
}
body(
"Send me something!"
)
}
priority 1
}
And I have included the following in my pom file:
<build>
<plugins>
<plugin>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-maven-plugin</artifactId>
<version>1.2.2.RELEASE</version>
<extensions>true</extensions>
<configuration>
<baseClassForTests>[baseClass link]</baseClassForTests>
</configuration>
</plugin>
</plugins>
</build>
As far as I can see, the line causing this problem is correct. Is there something else I could be missing?
EDIT:
On closer inspection, this seems to be the real cause of the issue:
java.lang.NoClassDefFoundError: io/restassured/internal/common/assertion/AssertParameter
java.lang.NoClassDefFoundError
The above error usually happens due to a mismatch between Spring Cloud and Spring Boot versions.
Spring Cloud releases are tied to specific Spring Boot versions. One can refer the following useful table in the Spring Cloud documentation:
Release train Spring Boot compatibility
Release Train
Boot Version
2021.0.x aka Jubilee
2.6.x, 2.7.x (Starting with 2021.0.3)
2020.0.x aka Ilford
2.4.x, 2.5.x (Starting with 2020.0.3)
Hoxton
2.2.x, 2.3.x (Starting with SR5)
Greenwich
2.1.x
Finchley
2.0.x
Edgware
1.5.x
Dalston
1.5.x
Note: It is recommended to use rest-assured that comes out of the box with Spring, to avoid any version mismatches.

Spring security auto configuration not working in spring boot 2.1.2.RELEASE

I have included spring security dependency in pom.xml but the endpoints are not getting secured by default .This is happening in spring boot version 2.1.2.RELEASE but when i switched back to 2.0.3.RELEASE, spring security is auto configured and all the endpoints are secured
I am not even getting the following line when using 2.1.2.RELEASE
Using default security password: ce6c3d39-8f20-4a41-8e01-803166bb99b6
Dependency added in pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>

Moving from Spring Boot 2.0.0.M6 to 2.0.0.M7 - dependencies.dependency.version' for org.springframework.social:spring-social-security:jar is missing

I'm trying to upgrade my application from Spring Boot 2.0.0.M6 to 2.0.0.M7
After upgrading my Maven application I ran into the following errors:
For example the following dependency
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-security</artifactId>
</dependency>
shows the following error:
Project build error: 'dependencies.dependency.version' for org.springframework.social:spring-social-security:jar is missing.
What am I doing wrong and how to fix it?
Dependency management and auto-configuration for Spring Social was removed from Spring Boot in 2.0 M7. The longer-term plan is for it to move into Spring Social itself but that has yet to happen.

Resources