swagger-ui.html shows a blank page in a Vaadin + Spring application - java

In my Spring+Vaadin (18) application I configured this:
vaadin.url-mapping=/ui/*
All Vaadin views are indeed accessible with a "localhost:8080/ui/something" address.
In the pom I have the required dependency for the Swagger UI:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>${springdoc.version}</version>
</dependency>
But the swagger-ui page returns full blank with the following console output by browsing to http://localhost:8080/swagger-ui.html which automatically redirects to http://localhost:8080/swagger-ui/index.html/?configUrl=/v3/api-docs/swagger-config.
The OpenAPI JSON page is accessible on http://localhost:8080/v3/api-docs/
Any idea why the Swagger UI page is not shown?

Related

How to change the Swagger UI path for a Spring Boot app using Sprinfgox?

I need to remove the "/swagger-ui" part from the Swagger UI URL. So far I have seen examples of how to add a prefix prior to the "/swagger-ui" such as "/prefix/swagger-ui" but I want to remove it completely and just have the prefix.
localhost:8080/swagger-ui -> localhost:8080/test
I have tried adding the following two to the .properties file but had no luck:
springdoc.swagger-ui.path=/test
springfox.documentation.swagger-ui.base-url=test
-spring-boot version: 2.5.6
I am using the below dependency for Springfox:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
I am wondering if there is any other way.

How to disable default /v3/api-docs definition in springdoc Swagger UI page?

I have my own OpenAPI specification YAML file which I can able to load in Swagger UI via /openapi-spec.yaml definition but the default /v3/api-docs is still exists. My goal is to disable the default /v3/api-docs and show only /openapi-spec.yaml as default.
Note: I'm using this dependency:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.9</version>
</dependency>
/v3/api-docs:
/openapi-spec.yaml
Try to add this property in your spring-boot configuration file:
springdoc.swagger-ui.path=/openapi-spec.yaml

JSP is downloading instead of rendering

My application was first downloading the jsp file instead of rendering it on page. I was getting a 200 status code in console but 404 on the page. I looked around and found I was suppose to add the dependencies for tomcat-jasper and tomcat-embed but now am getting a class cast exception saying that jspservlet can’t be cast to javax servlet. Any help appreciated. Thanks!
Getting an ApplicationContextException:
Caused by: javax.servlet.ServletException: Class [org.apache.jasper.servlet.JspServlet] is not a Servlet
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1054) ~[tomcat-embed-core-9.0.48.jar:9.0.48]
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:989) ~[tomcat-embed-core-9.0.48.jar:9.0.48]
at org.springframework.boot.web.embedded.tomcat.TomcatEmbeddedContext.load(TomcatEmbeddedContext.java:82) ~[spring-boot-2.5.2.jar:2.5.2]
... 32 common frames omitted
Caused by: java.lang.ClassCastException: org.apache.jasper.servlet.JspServlet cannot be cast to javax.servlet.Servlet
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1049) ~[tomcat-embed-core-9.0.48.jar:9.0.48]
... 34 common frames omitted
This happens when I have this in my pom:
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>10.1.0-M2</version>
<scope>runtime</scope>
</dependency>
When this is taken out of my pom everything works fine, hits the controller and returns the ModelAndView but downloads the jsp instead of actually displaying the page.
TL;DR: Use
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
There are a couple of problems with the dependency you added:
You should use tomcat-embed-jasper instead of tomcat-jasper: it depends on tomcat-embed-core (which is already used by Spring Boot) instead of tomcat-catalina (which is not used by Spring Boot). Including the latter causes problems like in this question.
Jasper 10.1 implements JSP 3.0, which is not compatible with Servlet 4.0 provided by Tomcat 9.0 (cf. this question). Since spring-boot-parent manages these dependencies, you should omit the <version> tag and use the version chosen by Spring Boot (9.0.48 for the version you are using, but it will keep in sync, when you update Spring Boot),
If you deploy your application as WAR file in an external servlet container, you want to use the version of JSP engine provided by the servlet container, instead of your own. Therefore you should set the scope to provided.

Customization of GraphiQL interface in Spring-Boot project

According to the GraphiQL README I can customize the interface by adding React children like this:
<GraphiQL.Logo>
My Custom Logo
</GraphiQL.Logo>
That is great, but how do I actually set these children? I'm not a web developer and I've never used React before! I'm developing a Spring-Boot project with the following dependencies:
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphql-spring-boot-starter</artifactId>
<version>5.0.6</version>
</dependency>
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphiql-spring-boot-starter</artifactId>
<version>5.0.6</version>
</dependency>
I don't see any way to set the children via application.properties/yml, although I can set other things there like the pageTitle, defaultQuery and editorTheme.
I can override the graphiql.html page provided by the starter. I naively tried to set the children like this at the end of the page:
// Render <GraphiQL /> into the body.
ReactDOM.render(
React.createElement(GraphiQL, props, [React.createElement('GraphiQL.Logo', {}, 'Custom LOGO')]),
document.body
);
That didn't have any effect.
How should I approach this?

Enable JSP Templating on Spring 4 with Maven

I'm trying to create an mvc web application using Spring.
I followed this guide http://spring.io/guides/gs/serving-web-content/
this works fine bur I don't understand how to use templates I'd like to have a header, footer to not repeat the code on each pages.
I'd like to use JSP but I don't understand how, there is no WEB-INF folder, no web.xml.
I don't know how to add .tag
Thanks for your help
Add file src/main/resources/application.properties with content
spring.view.prefix: /WEB-INF/jsp/
spring.view.suffix: .jsp
And dependency:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
Example project: spring-boot-web-jsp-example

Categories