I am trying to add the Swagger UI in my Spring Boot Application, but I am unable to access the swagger-ui.html.
pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-spring-webflux</artifactId>
<version>3.0.0</version>
</dependency>
Code:
#Configuration
public class SwaggerConfig {
#Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).select()
.apis(RequestHandlerSelectors.basePackage("com.learnings.search.web")).build().pathMapping("/")
.enableUrlTemplating(false);
}
}
#SpringBootApplication(exclude = { DataSourceAutoConfiguration.class, CassandraAutoConfiguration.class,
KafkaAutoConfiguration.class })
#EnableSwagger2
public class SearchApp {
public static void main(String[] args) {
SpringApplication.run(SearchApp.class, args);
}
}
I am able to access the swagger resources:
/swagger-resources
[
{
"name": "default",
"url": "/v2/api-docs",
"swaggerVersion": "2.0",
"location": "/v2/api-docs"
}
]
/swagger-resources/configuration/ui
{
"deepLinking": true,
"displayOperationId": false,
"defaultModelsExpandDepth": 1,
"defaultModelExpandDepth": 1,
"defaultModelRendering": "example",
"displayRequestDuration": false,
"docExpansion": "none",
"filter": false,
"operationsSorter": "alpha",
"showExtensions": false,
"showCommonExtensions": false,
"tagsSorter": "alpha",
"validatorUrl": "",
"supportedSubmitMethods": [
"get",
"put",
"post",
"delete",
"options",
"head",
"patch",
"trace"
],
"swaggerBaseUiUrl": ""
}
Please let me know if something has changed in the latest version, because I have been using the swagger-ui in my other projects.
In 3.0.0 swagger-ui.html has been moved to swagger-ui/index.html
You need to add this dependency also If using swagger 3 version.
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
Also, add #EnableOpenApi annotation in main class in Springboot application.
Hope this will work. Thanks!
Related
In my maven pom I have:
<properties>
<suppressions>./suppressions.json</suppressions>
</properties>
<plugin>
<groupId>dev.iabudiab</groupId>
<artifactId>dependency-track-maven-plugin</artifactId>
<version>2.1.0</version>
</plugin>
And in the root of my project I have a suppressions.json like this:
{
"suppressions": [
{
"by": "cve",
"cve": "CVE-2020-7019",
"expiration": "2024-12-31",
"note": "Bladi bla, reason because bladi"
}
]
}
Yet, after my build in Bamboo I still see CVE-2020-7019 between the vulnerabilities.
My target is I have spring boot application kafka producer with Avro serializing property and i am excepting the message which is pushed to respective topic that should access by confluent Sink Connector and insert into mysql/Oracle database tables , am able to produce Avro serialize and spring boot consumer can Avro deserialize but my Sink connector is not working , I am not able to catch what kind of payload sink connector is excepting and how should be spring boot producer coded to push message such a way that sink connector can cop-up with that properties
Thanks in advance :)
This is application.yml in spring boot application
server:
port: 9000
spring.kafka:
bootstrap-servers: "localhost:9092"
properties:
schema.registry.url: "http://localhost:8081"
specific.avro.reader: true
producer:
key-serializer: "io.confluent.kafka.serializers.KafkaAvroSerializer"
value-serializer: "io.confluent.kafka.serializers.KafkaAvroSerializer"
app:
topic: event_pay2
This is payload for creation of schema from spring boot application
{
"schema": {
"type": "struct",
"fields": [
{
"type": "string",
"optional": false,
"field": "userid"
},
{
"type": "string",
"optional": false,
"field": "regionid"
},
{
"type": "string",
"optional": false,
"field": "gender"
}
],
"optional": false,
"name": "oracle.user"
},
"payload": {
"userid": "User_1",
"regionid": "Region_5",
"gender": "FEMALE"
}
}
Pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.kafka</groupId>
<artifactId>kafka-producer-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>kafka-producer-example</name>
<description>Demo project for Spring Boot</description>
<repositories>
<repository>
<id>confluent</id>
<url>http://packages.confluent.io/maven</url>
</repository>
</repositories>
<properties>
<java.version>1.8</java.version>
<confluent.version>4.0.0</confluent.version>
</properties>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.confluent</groupId>
<artifactId>kafka-avro-serializer</artifactId>
<version>${confluent.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
<version>1.8.2</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>1.8.2</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>schema</goal>
</goals>
<configuration>
<sourceDirectory>${project.basedir}/src/main/resources/avro/</sourceDirectory>
<outputDirectory>${project.build.directory}/generated/avro</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
This is my rest call how am pushing messgae into kafka topic
#PostMapping("/publish/avrodata")
public String sendMessage(#RequestBody String request) {
sender.send(request);
return "Published successfully";
}
Finally My sink connector
"name": "JDBC_Sink_EVENT_PAY",
"connector.class": "io.confluent.connect.jdbc.JdbcSinkConnector",
"tasks.max": "1",
"topics": "event_pay2",
"connection.url": "jdbc:mysql://localhost:3306/user",
"connection.user": "****",
"connection.password": "****",
"auto.create": "true",
"auto.evolve":"true",
"key.converter": "io.confluent.connect.avro.AvroConverter",
"key.converter.schema.registry.url": "http://localhost:8081",
"key.converter.schemas.enable": "true",
"value.converter": "io.confluent.connect.avro.AvroConverter",
"value.converter.schema.registry.url": "http://localhost:8081",
"value.converter.schemas.enable": "true"
Always, always debug your topic before setting up a Connector. Use kafka-avro-console-consumer for this. If that doesn't work, then Connect + AvroConverter likely won't work either (in my experience), and you can reduce the problem space.
If I read your code correctly, you've sent a String, and not an Avro object
public String sendMessage(#RequestBody String request) {
sender.send(request); // <--- here and ^^^^^^ here
return "Published successfully";
}
Instead, you need to parse your input request into an object that was created as part of your /src/main/resources/avro schema data, not just forward through the incoming request as a string.
And that AVSC file might look something like
{
"type": "Record",
"namespace": "oracle.user",
"name": "User",
"fields": [
{ "type": "string", "name: "user_id" },
{ "type": "string", "name": "regionid" },
{ "type" "string", "name" "gender" }
]
}
Which would create a oracle.user.User object, making your KafkaTemplate need to be something like KafkaTemplate<String, oracle.user.User> sender
I have an SpringBoot app. 2.1.3.RELEASE securized by JWT, I want to add an actuator. I added this dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
I have added this properties to the application.properties file
management.endpoints.web.exposure.include=health,info
management.endpoint.health.show-details=always
when I access to /actuator I got this response:
{
"_links": {
"self": {
"href": "http://127.0.0.1:1133/tdk/actuator",
"templated": false
},
"health": {
"href": "http://127.0.0.1:1133/tdk/actuator/health",
"templated": false
},
"health-component": {
"href": "http://127.0.0.1:1133/tdk/actuator/health/{component}",
"templated": true
},
"health-component-instance": {
"href": "http://127.0.0.1:1133/tdk/actuator/health/{component}/{instance}",
"templated": true
},
"info": {
"href": "http://127.0.0.1:1133/tdk/actuator/info",
"templated": false
}
}
}
but when I access to http://127.0.0.1:1133/tdk/actuator/info , I got only
{}
You need to add build-info goal to generate build information. see doc here for more info.
I have generated an spring boot + angular application . imported entities with jdl. working properly with h2 . I am newbie and want to use mysql.I have configured datasource in application-dev.yml with following code.
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:mysql://localhost:3306/blogdb?useUnicode=true&characterEncoding=utf8&useSSL=false
username: name
password:pass
h2:
console:
enabled: false
hikari:
data-source-properties:
cachePrepStmts: true
prepStmtCacheSize: 250
prepStmtCacheSqlLimit: 2048
useServerPrepStmts: true
jpa:
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
database: mysql
show-sql: true
2) I have updated my pom configuration from h2 to mysql with following code.
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>${liquibase.version}</version>
<configuration>
<changeLogFile>src/main/resources/config/liquibase/master.xml</changeLogFile>
<diffChangeLogFile>src/main/resources/config/liquibase/changelog/${maven.build.timestamp}_changelog.xml</diffChangeLogFile>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://localhost:3306/blogdb</url>
<defaultSchemaName>blogdb</defaultSchemaName>
<username>name</username>
<password>**</password>
<referenceUrl>hibernate:spring:pt.farol.destfinder.domain?dialect=org.hibernate.dialect.MySQLInnoDBDialect&hibernate.ejb.naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringNamingStrategy</referenceUrl>
<verbose>true</verbose>
<logging>debug</logging>
</configuration>
<dependencies>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>${javassist.version}</version>
</dependency>
<dependency>
<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-hibernate5</artifactId>
<version>${liquibase-hibernate5.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>${validation-api.version}</version>
</dependency>
</dependencies>
</plugin>
PROBLEM when i run my project i am getting following error .
The Class-Path manifest attribute in C:\..\..\.m2\repository\org\liquibase\liquibase-core\3.5.3\liquibase-core-3.5.3.jar referenced one or more files that do not exist: C:\..\.\.m2\repository\org\liquibase\liquibase-core\3.5.3\lib\snakeyaml-1.13.jar
22:58:49.740 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Included patterns for restart : []
22:58:49.751 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Excluded patterns for restart : [/spring-boot-starter/target/classes/, /spring-boot-autoconfigure/target/classes/, /spring-boot-starter-[\w-]+/, /spring-boot/target/classes/, /spring-boot-actuator/target/classes/, /spring-boot-devtools/target/classes/]
22:58:49.751 [main] DEBUG org.springframework.boot.devtools.restart.ChangeableUrls - Matching URLs for reloading : [file:/G:/Java%20Projects/target/classes/]
22:58:52.636 [restartedMain] DEBUG org.springframework.boot.logging.ClasspathLoggingApplicationListener - Application failed to start with classpath: [file:/G:/Java%20Projects/target/classes/]
Edit
git repository link
yo-rc.json file
{
"generator-jhipster": {
"promptValues": {
"packageName": "com.beam"
},
"jhipsterVersion": "4.10.2",
"baseName": "beam",
"packageName": "com.beam",
"packageFolder": "com/beam",
"serverPort": "8080",
"authenticationType": "session",
"hibernateCache": "ehcache",
"clusteredHttpSession": false,
"websocket": false,
"databaseType": "sql",
"devDatabaseType": "mysql",
"prodDatabaseType": "mysql",
"searchEngine": false,
"messageBroker": false,
"serviceDiscoveryType": false,
"buildTool": "maven",
"enableSocialSignIn": false,
"enableSwaggerCodegen": false,
"rememberMeKey": "801a22f60c33f866035c634e04c3b5b096fdedc6",
"clientFramework": "angularX",
"useSass": true,
"clientPackageManager": "yarn",
"applicationType": "monolith",
"testFrameworks": [],
"jhiPrefix": "jhi",
"enableTranslation": false
}
}
This is not an answer but I needed more space than in comments.
I have generated an app using your .yo-rc.json file and jhipster 4.10.2, it works fine. I also have the Class-Path manifest warning but it's harmless and the application works.
[INFO] --- spring-boot-maven-plugin:1.5.7.RELEASE:run (default-cli) # beam ---
[INFO] Attaching agents: []
The Class-Path manifest attribute in C:\Users\Gaël\.m2\repository\org\liquibase\liquibase-core\3.5.3\liquibase-core-3.5.3.jar referenced one or more files tha
t do not exist: C:\Users\Gaël\.m2\repository\org\liquibase\liquibase-core\3.5.3\lib\snakeyaml-1.13.jar
22:15:34.613 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Included patterns for restart : []
22:15:34.617 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Excluded patterns for restart : [/spring-boot-starter/target/classes/,
2017-11-13 22:15:57.237 INFO 20472 --- [ restartedMain] com.beam.BeamApp :
----------------------------------------------------------
Application 'beam' is running! Access URLs:
Local: http://localhost:8180
External: http://172.27.112.1:8180
Profile(s): [swagger, dev]
----------------------------------------------------------
So, I guess you're not pasting the real error.
What exactly is the symptom?
Try to create a new jhipster application, and choose Mysql at the creation moment. It takes few minutes, and you can check and compare.
Normally in application-dev.yml spacing is considered so in password to be
yours,
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:mysql://localhost:3306/blogdb?useUnicode=true&characterEncoding=utf8&useSSL=false
username: name
password:pass
what to be done is,
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:mysql://localhost:3306/blogdb?useUnicode=true&characterEncoding=utf8&useSSL=false
username: name
password: pass
just check it out
When I tried to install a JHipster project with Mysql, I had the same problem, My problem got resolved when I Change
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:mysql://localhost:3306/blogdb?useUnicode=true&characterEncoding=utf8&useSSL=false
username: name
password:pass
to
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:mysql://localhost:3306/blogdb /*Removed the parameters*/
username: name
password:pass
I had the same error if you are using docker, so replace localhost to your docker IP
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:mysql://192.168.99.100:3306/library
username: root
I am a newbiew of ReactJS. Before, I used ReactJS for my company's project but actually that project has configurated by somone. I just apply what I know about Reactjs into project such as : state, props, component, apply redux.....
But , now I want to create a project by myself step by step. In that I can use reactjs integrate redux to manage state for using data and Spring is server in RESTfull standard and combine with JPA
Please help me
You can integrate spring and react js using 2 approaches
You can do it by making an isomorphic web app which uses nashorn engine(jdk8).
You can use pusher api(I have used pusher api in my app)
As i can not explain the full working here,here are tutorials for reference
using pusher api
isomorphic wb app
There is no simple answer.
You can use maven plugin https://github.com/eirslett/frontend-maven-plugin
Add to your pom.xml something like this
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.2</version>
<configuration>
<installDirectory>target</installDirectory>
</configuration>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>v4.4.5</nodeVersion>
<npmVersion>3.9.2</npmVersion>
</configuration>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>webpack build</id>
<goals>
<goal>webpack</goal>
</goals>
</execution>
</executions>
</plugin>
and you need to add package.json like this
{
"dependencies": {
"react": "^15.4.2",
"react-dom": "^15.4.2",
"requirejs": "^2.3.2"
},
"devDependencies": {
"babel-core": "^6.22.1",
"babel-loader": "^6.2.10",
"babel-plugin-transform-regenerator": "^6.22.0",
"babel-preset-es2015": "^6.22.0",
"babel-preset-react": "^6.22.0",
"babel-preset-stage-0": "^6.22.0",
"react-frame-component": "^0.6.6",
"webpack": "^2.2.1",
"webpack-dev-server": "^2.3.0"
},
"scripts": {
"start": "webpack-dev-server --progress --inline --hot",
"build": "webpack -d"
}
}
But list of dependenccies is yours
And you need webpack.config.js something like this
var path = require('path');
var webpack = require('webpack');
var packageJSON = require('./package.json');
module.exports = {
entry: [
'webpack/hot/only-dev-server',
'./src/main/resources/static/App.js'],
devtool: 'sourcemaps',
cache: true,
output: {
path: __dirname,
filename: './src/main/resources/static/built/bundle.js',
publicPath: 'http://localhost:3000/'
},
resolve: {extensions: ['.js', '.jsx']},
plugins: [
new webpack.HotModuleReplacementPlugin()
,new webpack.LoaderOptionsPlugin({
debug: true
})
],
module: {
loaders: [
{
test: path.join(__dirname, '.'),
exclude: /(node_modules)/,
loader: 'babel-loader',
query: {
cacheDirectory: true,
presets: ['es2015', 'react']
}
},
]
},
devServer: {
noInfo: false,
quiet: false,
lazy: false,
watchOptions: {
poll: true
}
}
};