Sunday, 11 June 2017
Add Swagger to gradle SpringBoot application
Swagger is useful for contracts between controller and UI developer. Also, We can do TESTING the of the controller URLs with the help of swagger UI.
Add below steps to add swagger in graddle springboot App:
1. gradle dependencies in build.gradle
compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.4.0'
compile group: 'net.bull.javamelody', name: 'javamelody-core', version: '1.54.0'
2. Create SwaggerConfig class in config package
SwaggerConfig.java:
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket newsApi() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName(<packaage>)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("<controller_package>"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title(<title>)
.description(<description>)
.termsOfServiceUrl("https://www.xyz.com/en/terms")
.license("Xyz License")
.licenseUrl("https://www.xyz.com")
.version("1.0")
.build();
}
}
There are more option to configure Docket. above are commonly used.
3. To get the UI page for swagger
Start springBoot project
Hit below URL:
http://<server>:<port>/<project_name>/swagger-ui.html
Congratullations!! Its done! !!
Add below steps to add swagger in graddle springboot App:
1. gradle dependencies in build.gradle
compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.4.0'
compile group: 'net.bull.javamelody', name: 'javamelody-core', version: '1.54.0'
2. Create SwaggerConfig class in config package
SwaggerConfig.java:
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket newsApi() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName(<packaage>)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("<controller_package>"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title(<title>)
.description(<description>)
.termsOfServiceUrl("https://www.xyz.com/en/terms")
.license("Xyz License")
.licenseUrl("https://www.xyz.com")
.version("1.0")
.build();
}
}
There are more option to configure Docket. above are commonly used.
3. To get the UI page for swagger
Start springBoot project
Hit below URL:
http://<server>:<port>/<project_name>/swagger-ui.html
Congratullations!! Its done! !!
Shell script to deploy build and start SpringBoot project on Linux/Ubuntu
Provide the below paths at top in below test.sh file:
Step1: Run with gradlew
create below gradle.sh file.
gradle.sh :
export GRADLE_HOME=/opt/gradle/gradle-3.0;
export PATH="$PATH:$GRADLE_HOME/bin";
cd <PROJECT_HOME_PATH>;
gradle clean bootRun -PdebugPort=8000 --debug ;
---------------------------------------------------------------------
$sh gradle.sh ---for runing sh file
Step2: Run with nohup, So we can close console
for Better use, create below folders:
-- /<my-dir>/checkouts - Here cheeckout/copy springboot project
--/<my-dir>/deployment - here we we will add bootPackage run details from /<my-dir>checkouts/<project>/build/app-classpath/* and /<my-dir>checkouts/<project>/build/libs/<project-version.jar>
Steps:
1. checkout gradle project in /<my-dir>/<gradle_project>
2. go to /<my-dir>/<gradle_project> and run below commands
chmod +x gradlew
./gradlew clean eclipse
./gradlew clean bootRepackage -Pprofile=<local/qa9>
3. copy /<my-dir>checkouts/<project>/build/app-classpath/* to <my-dir>/deployment/<gradle_project_name>/config/ folder. here we need to create confiig folder before copy
4.copy /<my-dir>checkouts/<project>/build/libs/<project-version.jar> to /<my-dir>/deployment/<project>/
5. go to /<my-dir>/deployment/<project>/
6. Run below nohup command
nohup java -Dloader.path="config/*" -Xms256m -Xmx1024m -jar <project-version.jar> --spring.config.location=config/<gradle_project_name>.yml --logging.config=config/log4j2-spring.yml --spring.profiles.active=<local/qa9> > console.log &
To automate above steps in shell script: below is deploy.sh file:
Steps:
1. Put this deploy.sh file in checkouts/<projectName>/ path
2. Make sure Checkouts and deployment folder at parallel
3. run sh deploy.sh <profile_name> command from terminal
deploy.sh:
--------------------------------
project_root_dir="$PWD"
profile=$1;
project_name=$( echo $project_root_dir | rev | cut -d/ -f1 | rev);
echo "Project name: $project_name";
deployment_dir=$project_root_dir/../../deployment;
echo "Deploy project profile : $profile";
echo "project root dir: $project_root_dir";
cd $project_root_dir;
pwd;
cd $deployment_dir;
pwd;
echo "Creating project folder in deployment";
echo "Removing config and jar";
rm -rf $project_name/config $project_name/content*.jar;
echo "Removed config and jar";
mkdir $deployment_dir/$project_name;
cd $deployment_dir/$project_name;
pwd;
ls;
mkdir config;
echo "Dir created :$project_root_dir/../../deployment/config ";
echo "Creating jar and config the springBoot project";
cd $project_root_dir;
chmod +x gradlew;
./gradlew clean eclipse;
./gradlew clean bootRepackage -Pprofile=$profile;
date;
echo "Copying jar and config folder to deployment folder";
cp -r $project_root_dir/build/app-classpath/* $deployment_dir/$project_name/config;
echo "Copied $project_root_dir/../../deployment/$project_name/config";
cd $project_root_dir/../../deployment/$project_name/config;
ls -lart;
cp -r $project_root_dir/build/libs/content*.jar $deployment_dir/$project_name/;
echo "Copied jar file";
cd $deployment_dir/$project_name;
ls -lart;
echo "Runing Jar Dir:$pwd";
echo "Running jar with nohup";
echo "nohup java -Dloader.path=config/* -Xms256m -Xmx512m -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:"$project_name"_gc.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=20000k -XX:+UseG1GC -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath="$project_name"_java_pid.hprof -jar "$project_name"-1.0.0.jar --spring.config.location=config/"$project_name".yml --logging.config=config/log4j2-spring.yml --spring.profiles.active=$profile > console.log &";
nohup java -Dloader.path=config/* -Xms256m -Xmx512m -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:"$project_name"_gc.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=20000k -XX:+UseG1GC -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath="$project_name"_java_pid.hprof -jar "$project_name"-1.0.0.jar --spring.config.location=config/"$project_name".yml --logging.config=config/log4j2-spring.yml --spring.profiles.active=$profile > console.log &
tail -f console.log;
-----------------------------------
Step1: Run with gradlew
create below gradle.sh file.
gradle.sh :
export GRADLE_HOME=/opt/gradle/gradle-3.0;
export PATH="$PATH:$GRADLE_HOME/bin";
cd <PROJECT_HOME_PATH>;
gradle clean bootRun -PdebugPort=8000 --debug ;
---------------------------------------------------------------------
$sh gradle.sh ---for runing sh file
Step2: Run with nohup, So we can close console
for Better use, create below folders:
-- /<my-dir>/checkouts - Here cheeckout/copy springboot project
--/<my-dir>/deployment - here we we will add bootPackage run details from /<my-dir>checkouts/<project>/build/app-classpath/* and /<my-dir>checkouts/<project>/build/libs/<project-version.jar>
Steps:
1. checkout gradle project in /<my-dir>/<gradle_project>
2. go to /<my-dir>/<gradle_project> and run below commands
chmod +x gradlew
./gradlew clean eclipse
./gradlew clean bootRepackage -Pprofile=<local/qa9>
3. copy /<my-dir>checkouts/<project>/build/app-classpath/* to <my-dir>/deployment/<gradle_project_name>/config/ folder. here we need to create confiig folder before copy
4.copy /<my-dir>checkouts/<project>/build/libs/<project-version.jar> to /<my-dir>/deployment/<project>/
5. go to /<my-dir>/deployment/<project>/
6. Run below nohup command
nohup java -Dloader.path="config/*" -Xms256m -Xmx1024m -jar <project-version.jar> --spring.config.location=config/<gradle_project_name>.yml --logging.config=config/log4j2-spring.yml --spring.profiles.active=<local/qa9> > console.log &
To automate above steps in shell script: below is deploy.sh file:
Steps:
1. Put this deploy.sh file in checkouts/<projectName>/ path
2. Make sure Checkouts and deployment folder at parallel
3. run sh deploy.sh <profile_name> command from terminal
deploy.sh:
--------------------------------
project_root_dir="$PWD"
profile=$1;
project_name=$( echo $project_root_dir | rev | cut -d/ -f1 | rev);
echo "Project name: $project_name";
deployment_dir=$project_root_dir/../../deployment;
echo "Deploy project profile : $profile";
echo "project root dir: $project_root_dir";
cd $project_root_dir;
pwd;
cd $deployment_dir;
pwd;
echo "Creating project folder in deployment";
echo "Removing config and jar";
rm -rf $project_name/config $project_name/content*.jar;
echo "Removed config and jar";
mkdir $deployment_dir/$project_name;
cd $deployment_dir/$project_name;
pwd;
ls;
mkdir config;
echo "Dir created :$project_root_dir/../../deployment/config ";
echo "Creating jar and config the springBoot project";
cd $project_root_dir;
chmod +x gradlew;
./gradlew clean eclipse;
./gradlew clean bootRepackage -Pprofile=$profile;
date;
echo "Copying jar and config folder to deployment folder";
cp -r $project_root_dir/build/app-classpath/* $deployment_dir/$project_name/config;
echo "Copied $project_root_dir/../../deployment/$project_name/config";
cd $project_root_dir/../../deployment/$project_name/config;
ls -lart;
cp -r $project_root_dir/build/libs/content*.jar $deployment_dir/$project_name/;
echo "Copied jar file";
cd $deployment_dir/$project_name;
ls -lart;
echo "Runing Jar Dir:$pwd";
echo "Running jar with nohup";
echo "nohup java -Dloader.path=config/* -Xms256m -Xmx512m -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:"$project_name"_gc.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=20000k -XX:+UseG1GC -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath="$project_name"_java_pid.hprof -jar "$project_name"-1.0.0.jar --spring.config.location=config/"$project_name".yml --logging.config=config/log4j2-spring.yml --spring.profiles.active=$profile > console.log &";
nohup java -Dloader.path=config/* -Xms256m -Xmx512m -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:"$project_name"_gc.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=20000k -XX:+UseG1GC -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath="$project_name"_java_pid.hprof -jar "$project_name"-1.0.0.jar --spring.config.location=config/"$project_name".yml --logging.config=config/log4j2-spring.yml --spring.profiles.active=$profile > console.log &
tail -f console.log;
-----------------------------------
Download WebStorm IDE for angular 4
it000483@IND-PUN-LAP-183:~/angular4$ wget https://download.jetbrains.com/webstorm/WebStorm-2017.1.4.tar.gz
--2017-06-11 15:43:17--
https://download.jetbrains.com/webstorm/WebStorm-2017.1.4.tar.gz
Resolving download.jetbrains.com (download.jetbrains.com)...
54.217.236.18
Connecting to download.jetbrains.com
(download.jetbrains.com)|54.217.236.18|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location:
https://download-cf.jetbrains.com/webstorm/WebStorm-2017.1.4.tar.gz
[following]
--2017-06-11 15:43:22--
https://download-cf.jetbrains.com/webstorm/WebStorm-2017.1.4.tar.gz
Resolving download-cf.jetbrains.com (download-cf.jetbrains.com)...
52.222.135.71, 52.222.135.249, 52.222.135.30, ...
Connecting to download-cf.jetbrains.com
(download-cf.jetbrains.com)|52.222.135.71|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 251746799 (240M) [binary/octet-stream]
Saving to: ‘WebStorm-2017.1.4.tar.gz’
Angular 4 Introduction and Install
Introduction:
Site for Referrence
: https://cli.angular.io/
Angular1 – based
on MVC model
angular2 – based
on component
angular4 –
performance better than angular 2
npm - node package
management
npm install -g
@angular/cli
download and install
npm – 3.10 greater
node -v
npm -v
ng -v
Creating project:
ng new <projectName>
--skip-install
cd <projectName>
ng serve – for
starting the app
localhost:4200 --by
default
-- To change port:
ng serve --host
0.0.0.0 --port 4201
Subscribe to:
Posts (Atom)
Extract error records while inserting into db table using JDBCIO apache beam in java
I was inserting data into postgres db using apache beam pipeline. it works perfectly with JdbcIO write of apache beam library. But, now, i ...
-
Hi, I was trying to register eureka clients with Eureka server using springboot application module as a client. I was getting below err...
-
I was trying to import git repo in eclipse. it was imported successfully but when I tried to push changes to upstream, I found 'git: c...
-
I was inserting data into postgres db using apache beam pipeline. it works perfectly with JdbcIO write of apache beam library. But, now, i ...