I'm trying to add swagger-ui (OpenAPI 3.0) to a Spring Boot v3 application.
I've added the openapi-ui maven dependency, and it should work as per the documentation.
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.11</version>
</dependency>
But apparently, it still doesn't work and localhost:8080/swagger-ui.html returns an 404 error.
What am I missing?
According to the documentation:
For spring-boot 3 support, make sure you use springdoc-openapi v2
https://springdoc.org/v2/
For the integration between spring-boot and swagger-ui, add the
library to the list of your project dependencies (No additional
configuration is needed)
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.0</version>
</dependency>
This will automatically deploy swagger-ui to a spring-boot
application:
Documentation will be available in HTML format, using the official
swagger-ui jars
The Swagger UI page will then be available at
http://server:port/context-path/swagger-ui.html and the OpenAPI
description will be available at the following url for json format:
http://server:port/context-path/v3/api-docs
server: The server name or IP
port: The server port
context-path: The context path of the application
Documentation can be available in yaml format as well, on the following path : /v3/api-docs.yaml
Please note that modules have been renamed:
https://springdoc.org/v2/#migrating-from-springdoc-v1
I completely agreed with #JCompetence. Please note that
springdoc-openapi-ui now changed to springdoc-openapi-starter-webmvc-ui
from spring boot 3.
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.2</version>
</dependency>
Please try this. If you want to find more info, please check the official link:
https://springdoc.org/v2/#features
For me it helped, just changed the dependency
implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.11'
to
implementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-ui', version: '2.0.0'
or
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.0</version>
</dependency>
springdoc-openapi-starter-webmvc-ui doesn't work with spring-boot-starter-webflux
until you include spring-boot-starter-web.
If you include spring security then it is dead.
Maven plugin to generate (Java) code from OpenApi spec (.yml files)
Generator “spring” supports Jakarta namespace
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<configuration>
<configOptions>
...
**<useSpringBoot3>true</useSpringBoot3>**
</configOptions>
</configuration>
</plugin>
Generator “java” (to generate a client) doesn’t support Jakarta namespace yet.
So use the Eclipse Transformer plugin (Javax dependencies need provided scope!)
<plugin>
<groupId>org.eclipse.transformer</groupId>
<artifactId>transformer-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<rules>
<jakartaDefaults>true</jakartaDefaults>
</rules>
</configuration>
<executions>
<execution>
<id>jakarta-ee</id>
<goals><goal>jar</goal></goals>
<phase>package</phase>
<configuration>
<artifact>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
</artifact>
</configuration>
</execution>
</executions>
</plugin>
Related
I generated the code using a maven plugin and the code does not compile.
https://sap.github.io/cloud-sdk/docs/java/features/odata/generate-typed-odata-v2-and-v4-client-for-java
I am using the odata V2 Plugin
I am not sure how to resolve this compilation issue:
The method getHttpClient(String) in the type HttpClientAccessor is not applicable for the arguments (HttpDestinationProperties)
Here is my pom file.
<dependency>
<groupId>com.sap.cloud.s4hana.datamodel</groupId>
<artifactId>odata-core</artifactId>
<version>2.28.0</version> </dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> <dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version> </dependency>
<!-- https://mvnrepository.com/artifact/javax.inject/javax.inject --> <dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version> </dependency>
com.sap.cloud.sdk.datamodel
odata-generator-maven-plugin
3.59.0
You're referring to correct documentation but the version number is your pom is incorrect.
In the documentation, it says 3.x.x, which as of 10.12.2022 would be 3.59.0.
<plugin>
<groupId>com.sap.cloud.sdk.datamodel</groupId>
<artifactId>odata-generator-maven-plugin</artifactId>
<!-- Please use the latest version here-->
<version>3.XX.X</version>
<executions>
<execution>
<id>generate-consumption</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputDirectory>${project.basedir}/edmx</inputDirectory>
<outputDirectory>${project.build.directory}/vdm</outputDirectory>
<deleteOutputDirectory>true</deleteOutputDirectory>
<packageName>com.mycompany.vdm</packageName>
<defaultBasePath>odata/v2/</defaultBasePath>
<compileScope>COMPILE</compileScope>
<serviceMethodsPerEntitySet>true</serviceMethodsPerEntitySet>
<!-- (Optional) You can add a custom copyright header:
<copyrightHeader>Copyright (c) this year, my company</copyrightHeader>
Or use the SAP copyright header:
<sapCopyrightHeader>true</sapCopyrightHeader>
-->
</configuration>
</execution>
</executions>
</plugin>
It feels like you're using an existing project based on an outdated and deprecated SDK version. Could you try generating a new project and use the maven plugin from there?
You can also check out if the service you're going to use has a pregenrated client library on the SAP API Business Hub. Check this one for example https://api.sap.com/api/API_COSTCENTERACTIVITYTYPE_SRV/cloud-sdk/Java
I am trying to generate stub using protobuf.
My pom.xml has below code
<plugin>
<groupId>com.github.os72</groupId>
<artifactId>protoc-jar-maven-plugin</artifactId>
<version>3.8.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<protocVersion>3.8.0</protocVersion>
<includeStdTypes>true</includeStdTypes>
<inputDirectories>
<include>src/main/proto</include>
</inputDirectories>
<outputTargets>
<outputTarget>
<type>java</type>
</outputTarget>
<outputTarget>
<type>grpc-java</type>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.24.0</pluginArtifact>
</outputTarget>
</outputTargets>
</configuration>
</execution>
</executions>
</plugin>
However, it generates the source files with target as Java1.8.
I am migrating my apps to Java 11, and have included the below jars in pom.xml file:
<dependency>
<groupId>com.sun.activation</groupId>
<artifactId>javax.activation</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.activation-api</artifactId>
<version>1.3.2</version>
</dependency>
However maven protoc plugin generates the files Grpc.java with annotnation javax.annotation.Generated instead of javax.annotation.api.Generated
Is there any other way for generating the java stub with target version as JDK 11.
If you follow the grpc-java documentation, it instructs you to use:
<dependency> <!-- necessary for Java 9+ -->
<groupId>org.apache.tomcat</groupId>
<artifactId>annotations-api</artifactId>
<version>6.0.53</version>
<scope>provided</scope>
</dependency>
Previous versions of the examples used javax.annotation:javax.annotation-api:1.2, which does work, but it was replaced with Tomcat for licensing reasons. In your pom.xml, it seems you might have mixed up "activation" vs "annotation", which look pretty similar at a glance.
I'm not aware of a javax.annotation.api.Generated annotation. I've not seen any real evidence that javax.annotation.processing.Generated is an appropriate replacement for javax.annotation.Generated either.
Im using liquibase in a standard java project (non spring) and using maven to manage my migrations and rollbacks
to the plugin configuration in maven im passing a liquibase.properties file that currently has a plain password in it
here is the relevant code
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>4.3.3</version>
<configuration>
<propertyFile>src/main/resources/liquibase.properties</propertyFile>
</configuration>
<executions>
<execution>
<phase>process-resources</phase>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-postgresql</artifactId>
<version>4.3.3</version>
</dependency>
</dependencies>
</plugin>
and the properties file
driver=org.postgresql.Driver
url=jdbc:postgresql://localhost:5432/testdb
username=test
password=test
changeLogFile=src/main/resources/db/changelog-master.xml
how can i avoid this
You may use your own property provider class to handle encryption. I don't see any docs for this but you can browse the commits on this link, it might help.
Also the answer on this post will help you with using propertyProviderClass in liquibase.
Other than this, you can go through this article to have an idea.
I'm developing a Java application using Apache Spark. I use this version:
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.10</artifactId>
<version>1.2.2</version>
</dependency>
In my code, there is a transitional dependency:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
I package my application into a single JAR file. When deploying it on EC2 instance using spark-submit, I get this error.
Caused by: java.lang.NoSuchFieldError: INSTANCE
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:144)
at com.amazonaws.http.apache.client.impl.ApacheConnectionManagerFactory.getPreferredSocketFactory(ApacheConnectionManagerFactory.java:87)
at com.amazonaws.http.apache.client.impl.ApacheConnectionManagerFactory.create(ApacheConnectionManagerFactory.java:65)
at com.amazonaws.http.apache.client.impl.ApacheConnectionManagerFactory.create(ApacheConnectionManagerFactory.java:58)
at com.amazonaws.http.apache.client.impl.ApacheHttpClientFactory.create(ApacheHttpClientFactory.java:50)
at com.amazonaws.http.apache.client.impl.ApacheHttpClientFactory.create(ApacheHttpClientFactory.java:38)
This error shows clearly that SparkSubmit has loaded an older version of the same Apache httpclient library and this conflict happens for this reason.
What is a good way to solve this issue?
For some reason, I cannot upgrade Spark on my Java code. However, I could do that with the EC2 cluster easily. Is it possible to deploy my java code on a cluster with a higher version say 1.6.1 version?
As said in your post, Spark is loading an older version of the httpclient. The solution is to use the Maven's relocation facility to produce a neat conflict-free project.
Here's an example of how to use it in your pom.xml file :
<project>
<!-- Your project definition here, with the groupId, artifactId, and it's dependencies -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>org.apache.http.client</pattern>
<shadedPattern>shaded.org.apache.http.client</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
This will move all files from org.apache.http.client to shaded.org.apache.http.client, resolving the conflict.
Original post :
If this is simply a matter of transitive dependencies, you could just add this to your spark-core dependency to exclude the HttpClient used by Spark :
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.10</artifactId>
<version>1.2.2</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</exclusion>
</exclusions>
</dependency>
I also added the scope as provided in your dependency as it will be provided by your cluster.
However, that might muck around with Spark's internal behaviour. If you still get an error after doing this, you could try using Maven's relocation facility that should produce a neat conflict-free project.
Regarding the fact you can't upgrade Spark's version, did you use exactly this dependency declaration from mvnrepository ?
Spark being backwards compatible, there shouldn't be any problem deploying your job on a cluster with a higher version.
I'm trying to generate a web service proxy using the wsdl2java tool that comes with Apache CXF. The generation itself seems to go just fine, but there are some errors in the generated files, a non-existing constructor is called.
The file offers a solution:
//This constructor requires JAX-WS API 2.2. You will need to endorse the 2.2
//API jar or re-run wsdl2java with "-frontend jaxws21" to generate JAX-WS 2.1
//compliant code instead.
So I set out to download and install the 2.2 version of the JAX-WS Api. I found the following installation manual explaining how to endorse these new files: http://dcx.sybase.com/1200/en/dbprogramming/httpserver-jaxws-lesson-two.html I followed every step of this guide, removed the old generated files and generated new ones, but the problem persists.
Any tips and/or tricks?
(now of course, I'm using the -frontend jaxws21 flag to generate the proxy, but still).
<defaultOptions>
<frontEnd>jaxws21</frontEnd>
</defaultOptions>
This is how I solved the issue using maven:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<id>generate-sources2</id>
<configuration>
<sourceRoot>${basedir}/target/generated-sources/cxf</sourceRoot>
<defaultOptions>
<frontEnd>jaxws21</frontEnd>
</defaultOptions>
<wsdlOptions>
<wsdlOption>
<wsdl>...</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
EDIT: I've found another way to solve this using maven and cxf version 2.7.3. Add these libraries in your dependencies. You now dont have to use the jaxws21 option:
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.2.9</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.7</version>
</dependency>