├── README.md
├── springboot-distribution-assembly
├── .classpath
├── .project
├── .settings
│ ├── org.eclipse.core.resources.prefs
│ ├── org.eclipse.jdt.core.prefs
│ ├── org.eclipse.m2e.core.prefs
│ └── org.eclipse.wst.common.project.facet.core.xml
├── README
├── common-service
│ ├── .classpath
│ ├── .project
│ ├── .settings
│ │ ├── org.eclipse.core.resources.prefs
│ │ ├── org.eclipse.jdt.core.prefs
│ │ ├── org.eclipse.m2e.core.prefs
│ │ └── org.eclipse.wst.common.project.facet.core.xml
│ ├── pom.xml
│ ├── src
│ │ └── main
│ │ │ └── java
│ │ │ └── com
│ │ │ └── rmz
│ │ │ └── common
│ │ │ ├── BackendRunner.java
│ │ │ └── CommonRestApplication.java
│ └── target
│ │ └── classes
│ │ └── META-INF
│ │ ├── MANIFEST.MF
│ │ └── maven
│ │ └── com.rmz
│ │ └── common-service
│ │ ├── pom.properties
│ │ └── pom.xml
├── distribution
│ ├── .classpath
│ ├── .project
│ ├── .settings
│ │ ├── org.eclipse.core.resources.prefs
│ │ ├── org.eclipse.jdt.core.prefs
│ │ └── org.eclipse.m2e.core.prefs
│ ├── dryRun.bat
│ ├── dryRun.sh
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── assembly.xml
├── first-service
│ ├── .classpath
│ ├── .project
│ ├── .settings
│ │ ├── org.eclipse.core.resources.prefs
│ │ ├── org.eclipse.jdt.core.prefs
│ │ ├── org.eclipse.m2e.core.prefs
│ │ └── org.eclipse.wst.common.project.facet.core.xml
│ ├── pom.xml
│ ├── src
│ │ ├── main
│ │ │ ├── java
│ │ │ │ └── com
│ │ │ │ │ └── rmz
│ │ │ │ │ └── first
│ │ │ │ │ ├── FirstApplication.java
│ │ │ │ │ ├── backendRunner
│ │ │ │ │ ├── CustomizationBean.java
│ │ │ │ │ └── FirstServiceBackendRunner.java
│ │ │ │ │ ├── config
│ │ │ │ │ └── SwaggerConfig.java
│ │ │ │ │ └── controller
│ │ │ │ │ └── FirstController.java
│ │ │ └── resources
│ │ │ │ ├── application-dev.yml
│ │ │ │ └── application.yml
│ │ └── test
│ │ │ └── java
│ │ │ └── com
│ │ │ └── rmz
│ │ │ └── first
│ │ │ └── AppTest.java
│ └── target
│ │ └── classes
│ │ ├── META-INF
│ │ ├── MANIFEST.MF
│ │ └── maven
│ │ │ └── com.rmz
│ │ │ └── first-service
│ │ │ ├── pom.properties
│ │ │ └── pom.xml
│ │ ├── application-dev.yml
│ │ └── application.yml
├── launcher
│ ├── .classpath
│ ├── .project
│ ├── .settings
│ │ ├── org.eclipse.core.resources.prefs
│ │ ├── org.eclipse.jdt.core.prefs
│ │ ├── org.eclipse.m2e.core.prefs
│ │ └── org.eclipse.wst.common.project.facet.core.xml
│ ├── pom.xml
│ ├── src
│ │ ├── main
│ │ │ ├── java
│ │ │ │ └── com
│ │ │ │ │ └── rmz
│ │ │ │ │ └── launcher
│ │ │ │ │ ├── LauncherApplication.java
│ │ │ │ │ └── MicroservicesStarter.java
│ │ │ └── resources
│ │ │ │ └── application.yml
│ │ └── test
│ │ │ └── java
│ │ │ └── com
│ │ │ └── rmz
│ │ │ └── launcher
│ │ │ └── AppTest.java
│ └── target
│ │ └── classes
│ │ ├── META-INF
│ │ ├── MANIFEST.MF
│ │ └── maven
│ │ │ └── com.rmz
│ │ │ └── launcher
│ │ │ ├── pom.properties
│ │ │ └── pom.xml
│ │ └── application.yml
├── pom.xml
└── second-service
│ ├── .classpath
│ ├── .project
│ ├── .settings
│ ├── org.eclipse.core.resources.prefs
│ ├── org.eclipse.jdt.core.prefs
│ ├── org.eclipse.m2e.core.prefs
│ └── org.eclipse.wst.common.project.facet.core.xml
│ ├── pom.xml
│ ├── src
│ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── rmz
│ │ │ │ └── second
│ │ │ │ ├── SecondApplication.java
│ │ │ │ ├── backendRunner
│ │ │ │ ├── CustomizationBean.java
│ │ │ │ └── SecondServiceBackendRunner.java
│ │ │ │ ├── config
│ │ │ │ └── SwaggerConfig.java
│ │ │ │ └── controller
│ │ │ │ └── SecondController.java
│ │ └── resources
│ │ │ ├── application-dev.yml
│ │ │ └── application.yml
│ └── test
│ │ └── java
│ │ └── com
│ │ └── rmz
│ │ └── second
│ │ └── AppTest.java
│ └── target
│ └── classes
│ ├── META-INF
│ ├── MANIFEST.MF
│ └── maven
│ │ └── com.rmz
│ │ └── second-service
│ │ ├── pom.properties
│ │ └── pom.xml
│ ├── application-dev.yml
│ └── application.yml
├── springboot-json-crud
├── .classpath
├── .project
├── .settings
│ ├── org.eclipse.core.resources.prefs
│ ├── org.eclipse.jdt.core.prefs
│ ├── org.eclipse.m2e.core.prefs
│ └── org.eclipse.wst.common.project.facet.core.xml
├── .springBeans
├── DEVELOPMENT.md
├── README
├── pom.xml
├── src
│ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── raydar
│ │ │ │ ├── CabaranApplication.java
│ │ │ │ ├── config
│ │ │ │ ├── AppConfig.java
│ │ │ │ ├── SpringEventsListener.java
│ │ │ │ └── SwaggerConfig.java
│ │ │ │ ├── controller
│ │ │ │ ├── CabaranController.java
│ │ │ │ └── EmployeeController.java
│ │ │ │ ├── domain
│ │ │ │ └── Employee.java
│ │ │ │ ├── dto
│ │ │ │ ├── BaseResponseDTO.java
│ │ │ │ ├── EmployeeDTO.java
│ │ │ │ └── EmployeeDataResponseDTO.java
│ │ │ │ ├── exception
│ │ │ │ ├── CustomizedResponseEntityExceptionHandler.java
│ │ │ │ ├── EmployeeNotFoundException.java
│ │ │ │ └── ErrorDetails.java
│ │ │ │ ├── filter
│ │ │ │ ├── EmployeeSpecification.java
│ │ │ │ ├── EmployeeSpecificationBuilder.java
│ │ │ │ ├── FilterOperation.java
│ │ │ │ ├── SearchCriteria.java
│ │ │ │ └── SortOperation.java
│ │ │ │ ├── repository
│ │ │ │ ├── EmployeeJpaRepository.java
│ │ │ │ ├── EmployeeJsonRepositoryImpl.java
│ │ │ │ └── IEmployeeJsonRepository.java
│ │ │ │ ├── service
│ │ │ │ ├── CacheServiceImpl.java
│ │ │ │ ├── EmployeeServiceImpl.java
│ │ │ │ ├── ICacheService.java
│ │ │ │ └── IEmployeeService.java
│ │ │ │ ├── util
│ │ │ │ ├── DTOBuilder.java
│ │ │ │ ├── JsonUtil.java
│ │ │ │ └── StringUtils.java
│ │ │ │ └── validator
│ │ │ │ └── EmployeeValidator.java
│ │ └── resources
│ │ │ ├── application-dev.yml
│ │ │ ├── application.yml
│ │ │ ├── logback.xml
│ │ │ ├── messages.properties
│ │ │ └── messages_my.properties
│ └── test
│ │ └── java
│ │ └── com
│ │ └── raydar
│ │ ├── EmployeesControllerTest.java
│ │ └── SpringBootApplicationTests.java
└── target
│ └── classes
│ ├── META-INF
│ ├── MANIFEST.MF
│ └── maven
│ │ └── com.raydar
│ │ └── cabaran
│ │ ├── pom.properties
│ │ └── pom.xml
│ ├── application-dev.yml
│ └── application.yml
├── springboot-multi-service-launcher
├── .classpath
├── .project
├── .settings
│ ├── org.eclipse.core.resources.prefs
│ ├── org.eclipse.jdt.core.prefs
│ ├── org.eclipse.m2e.core.prefs
│ └── org.eclipse.wst.common.project.facet.core.xml
├── README
├── common-service
│ ├── .classpath
│ ├── .project
│ ├── .settings
│ │ ├── org.eclipse.core.resources.prefs
│ │ ├── org.eclipse.jdt.core.prefs
│ │ ├── org.eclipse.m2e.core.prefs
│ │ └── org.eclipse.wst.common.project.facet.core.xml
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── rmz
│ │ └── common
│ │ ├── BackendRunner.java
│ │ └── CommonRestApplication.java
├── first-service
│ ├── .classpath
│ ├── .project
│ ├── .settings
│ │ ├── org.eclipse.core.resources.prefs
│ │ ├── org.eclipse.jdt.core.prefs
│ │ ├── org.eclipse.m2e.core.prefs
│ │ └── org.eclipse.wst.common.project.facet.core.xml
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── rmz
│ │ │ │ └── first
│ │ │ │ ├── FirstApplication.java
│ │ │ │ ├── backendRunner
│ │ │ │ ├── CustomizationBean.java
│ │ │ │ └── FirstServiceBackendRunner.java
│ │ │ │ ├── config
│ │ │ │ └── SwaggerConfig.java
│ │ │ │ └── controller
│ │ │ │ └── FirstController.java
│ │ └── resources
│ │ │ ├── application-dev.yml
│ │ │ └── application.yml
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── rmz
│ │ └── first
│ │ └── AppTest.java
├── launcher
│ ├── .classpath
│ ├── .project
│ ├── .settings
│ │ ├── org.eclipse.core.resources.prefs
│ │ ├── org.eclipse.jdt.core.prefs
│ │ ├── org.eclipse.m2e.core.prefs
│ │ └── org.eclipse.wst.common.project.facet.core.xml
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── rmz
│ │ │ │ └── launcher
│ │ │ │ ├── LauncherApplication.java
│ │ │ │ └── MicroservicesStarter.java
│ │ └── resources
│ │ │ └── application.yml
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── rmz
│ │ └── launcher
│ │ └── AppTest.java
├── pom.xml
└── second-service
│ ├── .classpath
│ ├── .project
│ ├── .settings
│ ├── org.eclipse.core.resources.prefs
│ ├── org.eclipse.jdt.core.prefs
│ ├── org.eclipse.m2e.core.prefs
│ └── org.eclipse.wst.common.project.facet.core.xml
│ ├── pom.xml
│ └── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── rmz
│ │ │ └── second
│ │ │ ├── SecondApplication.java
│ │ │ ├── backendRunner
│ │ │ ├── CustomizationBean.java
│ │ │ └── SecondServiceBackendRunner.java
│ │ │ ├── config
│ │ │ └── SwaggerConfig.java
│ │ │ └── controller
│ │ │ └── SecondController.java
│ └── resources
│ │ ├── application-dev.yml
│ │ └── application.yml
│ └── test
│ └── java
│ └── com
│ └── rmz
│ └── second
│ └── AppTest.java
├── springboot-sample-actuator
├── .classpath
├── .project
├── .settings
│ ├── org.eclipse.core.resources.prefs
│ ├── org.eclipse.jdt.core.prefs
│ ├── org.eclipse.m2e.core.prefs
│ └── org.eclipse.wst.common.project.facet.core.xml
├── .springBeans
├── README
├── pom.xml
├── src
│ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── rmz
│ │ │ └── actuator
│ │ │ ├── ActuatorApplication.java
│ │ │ ├── config
│ │ │ └── SwaggerConfig.java
│ │ │ └── controller
│ │ │ └── ActuatorController.java
│ │ └── resources
│ │ ├── application-dev.yml
│ │ └── application.yml
└── target
│ └── classes
│ ├── META-INF
│ ├── MANIFEST.MF
│ └── maven
│ │ └── com.rmz
│ │ └── springboot-sample-actuator
│ │ ├── pom.properties
│ │ └── pom.xml
│ ├── application-dev.yml
│ └── application.yml
└── springboot-sample-ssl
├── .classpath
├── .project
├── .settings
├── org.eclipse.core.resources.prefs
├── org.eclipse.jdt.core.prefs
├── org.eclipse.m2e.core.prefs
└── org.eclipse.wst.common.project.facet.core.xml
├── .springBeans
├── README
├── pom.xml
└── src
└── main
├── java
└── com
│ └── rmz
│ └── secured
│ ├── SecuredApplication.java
│ ├── config
│ └── SwaggerConfig.java
│ └── controller
│ └── SecuredController.java
└── resources
├── application-dev.yml
├── application.yml
└── sample-ssl-server.jks
/README.md:
--------------------------------------------------------------------------------
1 | # springboot-demo
2 | This repository will contain spring boot demo projects done to solve common use-cases
3 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | springboot-distribution-assembly
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.wst.common.project.facet.core.builder
10 |
11 |
12 |
13 |
14 | org.eclipse.jdt.core.javabuilder
15 |
16 |
17 |
18 |
19 | org.springframework.ide.eclipse.core.springbuilder
20 |
21 |
22 |
23 |
24 | org.springframework.ide.eclipse.boot.validation.springbootbuilder
25 |
26 |
27 |
28 |
29 | org.eclipse.m2e.core.maven2Builder
30 |
31 |
32 |
33 |
34 |
35 | org.springframework.ide.eclipse.core.springnature
36 | org.eclipse.jdt.core.javanature
37 | org.eclipse.m2e.core.maven2Nature
38 | org.eclipse.wst.common.project.facet.core.nature
39 |
40 |
41 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding/=UTF-8
3 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
3 | org.eclipse.jdt.core.compiler.compliance=1.8
4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5 | org.eclipse.jdt.core.compiler.source=1.8
6 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | activeProfiles=
2 | eclipse.preferences.version=1
3 | resolveWorkspaceProjects=true
4 | version=1
5 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/.settings/org.eclipse.wst.common.project.facet.core.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/README:
--------------------------------------------------------------------------------
1 | Prerequisite: Java8, Maven3+
2 |
3 | This is demo project to illustrate how to create a distribution assembly which is ready to run at anywhere. Here we have used maven's
4 | assembly plugin to build distribution and spring boot thin layout plugin to make it ready to ship and ready to run.
5 | Follow below steps to launch the microservices:
6 |
7 | 1) ~ cd springboot-distribution-assembly
8 | 2) mvn clean install package (This may take time as it ll resolve all the dependencies.)
9 | 3) This will build a distribution @ /springboot-distribution-assembly/distribution/target/distribution-0.0.1-SNAPSHOT
10 | This distribution is not ready to run yet as it doesn't have any of your native or thirdparty dependencies.
11 | 4) To do so run below commands
12 | ~cd /springboot-distribution-assembly/distribution/target/distribution-0.0.1-SNAPSHOT
13 | ~java -jar first-service-0.0.1-SNAPSHOT.jar --thin.dryrun --thin.root=.
14 | ~java -jar second-service-0.0.1-SNAPSHOT.jar --thin.dryrun --thin.root=.
15 |
16 | * --thin.dryrun this will warm up maven repository local to your distribution. You can find all your dependencies
17 | in distribution-0.0.1-SNAPSHOT/repository
18 | * --thin.root=. Make sure to out . which will refer to current directory and create repository in distribution.
19 |
20 | * You can write shell script to warm up repository for all services at once. Refer /distribution-0.0.1-SNAPSHOT/dryRun.sh
21 |
22 | 5) Now you can zip this distribution and ship it anywhere and start the services
23 |
24 | ~java -jar first-service-0.0.1-SNAPSHOT.jar --thin.root=.
25 | ~java -jar second-service-0.0.1-SNAPSHOT.jar --thin.root=.
26 |
27 | 6) This will launch both the microservice. You can use swagger doc for services:
28 | http://localhost:8110/first/swagger-ui.html
29 | http://localhost:8111/second/swagger-ui.html
30 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/common-service/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/common-service/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | common-service
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.wst.common.project.facet.core.builder
10 |
11 |
12 |
13 |
14 | org.eclipse.jdt.core.javabuilder
15 |
16 |
17 |
18 |
19 | org.springframework.ide.eclipse.core.springbuilder
20 |
21 |
22 |
23 |
24 | org.springframework.ide.eclipse.boot.validation.springbootbuilder
25 |
26 |
27 |
28 |
29 | org.eclipse.m2e.core.maven2Builder
30 |
31 |
32 |
33 |
34 |
35 | org.springframework.ide.eclipse.core.springnature
36 | org.eclipse.jdt.core.javanature
37 | org.eclipse.m2e.core.maven2Nature
38 | org.eclipse.wst.common.project.facet.core.nature
39 |
40 |
41 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/common-service/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//src/main/java=UTF-8
3 | encoding/=UTF-8
4 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/common-service/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
3 | org.eclipse.jdt.core.compiler.compliance=1.8
4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5 | org.eclipse.jdt.core.compiler.source=1.8
6 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/common-service/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | activeProfiles=
2 | eclipse.preferences.version=1
3 | resolveWorkspaceProjects=true
4 | version=1
5 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/common-service/.settings/org.eclipse.wst.common.project.facet.core.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/common-service/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.rmz
8 | springboot-distribution-assembly
9 | 0.0.1-SNAPSHOT
10 |
11 | common-service
12 | common-service
13 | http://maven.apache.org
14 |
15 | UTF-8
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | org.apache.maven.plugins
24 | maven-compiler-plugin
25 | 2.3.2
26 |
27 | ${java.version}
28 | ${java.version}
29 |
30 |
31 |
32 | org.springframework.boot
33 | spring-boot-maven-plugin
34 |
35 |
36 | org.springframework.boot.experimental
37 | spring-boot-thin-layout
38 | 1.0.3.RELEASE
39 |
40 |
41 |
42 | true
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/common-service/src/main/java/com/rmz/common/BackendRunner.java:
--------------------------------------------------------------------------------
1 | package com.rmz.common;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.context.ConfigurableApplicationContext;
5 |
6 | public abstract class BackendRunner {
7 | private ConfigurableApplicationContext appContext;
8 | private final Class>[] backendClasses;
9 |
10 | private Object monitor = new Object();
11 | private boolean shouldWait;
12 |
13 | protected BackendRunner(final Class>... backendClasses) {
14 | this.backendClasses = backendClasses;
15 | }
16 |
17 | public void run() {
18 | if(appContext != null) {
19 | throw new IllegalStateException("AppContext must be null to run this backend");
20 | }
21 | runBackendInThread();
22 | waitUntilBackendIsStarted();
23 | }
24 |
25 | private void waitUntilBackendIsStarted() {
26 | try {
27 | synchronized (monitor) {
28 | if(shouldWait) {
29 | monitor.wait();
30 | }
31 | }
32 | } catch (InterruptedException e) {
33 | throw new IllegalStateException(e);
34 | }
35 | }
36 |
37 | private void runBackendInThread() {
38 | final Thread runnerThread = new BackendRunnerThread();
39 | shouldWait = true;
40 | runnerThread.setContextClassLoader(backendClasses[0].getClassLoader());
41 | runnerThread.start();
42 | }
43 |
44 | public void stop() {
45 | SpringApplication.exit(appContext);
46 | appContext = null;
47 | }
48 |
49 | private class BackendRunnerThread extends Thread {
50 | @Override
51 | public void run() {
52 | appContext = SpringApplication.run(backendClasses, new String[]{});
53 | synchronized (monitor) {
54 | shouldWait = false;
55 | monitor.notify();
56 | }
57 | }
58 | }
59 | }
60 |
61 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/common-service/src/main/java/com/rmz/common/CommonRestApplication.java:
--------------------------------------------------------------------------------
1 | package com.rmz.common;
2 |
3 | import org.springframework.boot.autoconfigure.SpringBootApplication;
4 |
5 | @SpringBootApplication
6 | public class CommonRestApplication {
7 | public static void main(String...strings) throws Exception {
8 |
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/common-service/target/classes/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Implementation-Title: common-service
3 | Implementation-Version: 0.0.1-SNAPSHOT
4 | Built-By: Rameez.shikalgar
5 | Implementation-Vendor-Id: com.rmz
6 | Build-Jdk: 1.8.0_131
7 | Implementation-URL: http://maven.apache.org
8 | Created-By: Maven Integration for Eclipse
9 |
10 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/common-service/target/classes/META-INF/maven/com.rmz/common-service/pom.properties:
--------------------------------------------------------------------------------
1 | #Generated by Maven Integration for Eclipse
2 | #Fri Aug 17 12:50:03 IST 2018
3 | version=0.0.1-SNAPSHOT
4 | groupId=com.rmz
5 | m2e.projectName=common-service
6 | m2e.projectLocation=C\:\\Users\\Rameez.shikalgar\\git\\springboot-demo\\springboot-distribution-assembly\\common-service
7 | artifactId=common-service
8 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/common-service/target/classes/META-INF/maven/com.rmz/common-service/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.rmz
8 | springboot-distribution-assembly
9 | 0.0.1-SNAPSHOT
10 |
11 | common-service
12 | common-service
13 | http://maven.apache.org
14 |
15 | UTF-8
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | org.apache.maven.plugins
24 | maven-compiler-plugin
25 | 2.3.2
26 |
27 | ${java.version}
28 | ${java.version}
29 |
30 |
31 |
32 | org.springframework.boot
33 | spring-boot-maven-plugin
34 |
35 |
36 | org.springframework.boot.experimental
37 | spring-boot-thin-layout
38 | 1.0.3.RELEASE
39 |
40 |
41 |
42 | true
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/distribution/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/distribution/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | distribution
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.m2e.core.maven2Builder
15 |
16 |
17 |
18 |
19 |
20 | org.eclipse.jdt.core.javanature
21 | org.eclipse.m2e.core.maven2Nature
22 |
23 |
24 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/distribution/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding/=UTF-8
3 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/distribution/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
3 | org.eclipse.jdt.core.compiler.compliance=1.5
4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5 | org.eclipse.jdt.core.compiler.source=1.5
6 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/distribution/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | activeProfiles=
2 | eclipse.preferences.version=1
3 | resolveWorkspaceProjects=true
4 | version=1
5 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/distribution/dryRun.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | for %%f in (.\*.jar) do (
3 | echo "Warming up repository for %%f. Please wait..."
4 | java -jar %%f --thin.dryrun --thin.root=.
5 | )
6 | @echo "Done!!!"
--------------------------------------------------------------------------------
/springboot-distribution-assembly/distribution/dryRun.sh:
--------------------------------------------------------------------------------
1 | for file in .* *.jar; do if [[ $file == *.jar ]]; then echo "Warming up repository for $file. Please wait..."; java -jar $file --thin.dryrun --thin.root=.; fi done
--------------------------------------------------------------------------------
/springboot-distribution-assembly/distribution/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 |
6 | com.rmz
7 | springboot-distribution-assembly
8 | 0.0.1-SNAPSHOT
9 |
10 |
11 | distribution
12 | pom
13 |
14 | distribution
15 | http://maven.apache.org
16 |
17 |
18 |
19 |
20 | maven-assembly-plugin
21 | 2.2.2
22 |
23 |
24 |
25 | make-assembly
26 | package
27 |
28 |
29 | single
30 |
31 |
32 |
33 |
34 |
35 | false
36 |
37 |
38 | src/main/assembly.xml
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/distribution/src/main/assembly.xml:
--------------------------------------------------------------------------------
1 |
2 | distribution
3 | false
4 |
5 |
6 | dir
7 |
8 |
9 |
10 | true
11 |
12 | com.rmz:first-service:jar
13 |
14 |
15 | /
16 | false
17 |
18 |
19 |
20 | *
21 |
22 |
23 |
24 |
25 |
26 | /properties/ocr
27 | false
28 |
29 |
30 | src/main/resources
31 | /
32 |
33 |
34 |
35 |
36 |
37 |
38 | true
39 |
40 | com.rmz:second-service:jar
41 |
42 |
43 | /
44 | false
45 |
46 |
47 |
48 | *
49 |
50 |
51 |
52 |
53 |
54 | /properties/pdf
55 | false
56 |
57 |
58 | src/main/resources
59 | /
60 |
61 |
62 |
63 |
64 |
65 |
66 | true
67 |
68 | com.rmz:launcher:jar
69 |
70 |
71 | /
72 | false
73 |
74 |
75 |
76 | *
77 |
78 |
79 |
80 |
81 |
82 | /properties/SFDC
83 | false
84 |
85 |
86 | src/main/resources
87 | /
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 | dryRun.sh
96 | /
97 | false
98 |
99 |
100 | dryRun.bat
101 | /
102 | false
103 |
104 |
105 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/first-service/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/first-service/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | first-service
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.wst.common.project.facet.core.builder
10 |
11 |
12 |
13 |
14 | org.eclipse.jdt.core.javabuilder
15 |
16 |
17 |
18 |
19 | org.springframework.ide.eclipse.core.springbuilder
20 |
21 |
22 |
23 |
24 | org.springframework.ide.eclipse.boot.validation.springbootbuilder
25 |
26 |
27 |
28 |
29 | org.eclipse.m2e.core.maven2Builder
30 |
31 |
32 |
33 |
34 |
35 | org.springframework.ide.eclipse.core.springnature
36 | org.eclipse.jdt.core.javanature
37 | org.eclipse.m2e.core.maven2Nature
38 | org.eclipse.wst.common.project.facet.core.nature
39 |
40 |
41 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/first-service/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//src/main/java=UTF-8
3 | encoding//src/main/resources=UTF-8
4 | encoding//src/test/java=UTF-8
5 | encoding/=UTF-8
6 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/first-service/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
3 | org.eclipse.jdt.core.compiler.compliance=1.8
4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5 | org.eclipse.jdt.core.compiler.source=1.8
6 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/first-service/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | activeProfiles=
2 | eclipse.preferences.version=1
3 | resolveWorkspaceProjects=true
4 | version=1
5 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/first-service/.settings/org.eclipse.wst.common.project.facet.core.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/first-service/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.rmz
8 | springboot-distribution-assembly
9 | 0.0.1-SNAPSHOT
10 |
11 | first-service
12 | first-service
13 | http://maven.apache.org
14 |
15 | UTF-8
16 |
17 |
18 |
19 | com.rmz
20 | common-service
21 | ${project.version}
22 |
23 |
24 |
25 |
26 |
27 | org.springframework.boot
28 | spring-boot-maven-plugin
29 |
30 |
31 | org.springframework.boot.experimental
32 | spring-boot-thin-layout
33 | 1.0.3.RELEASE
34 |
35 |
36 |
37 | true
38 |
39 |
40 |
41 | org.apache.maven.plugins
42 | maven-compiler-plugin
43 | 2.3.2
44 |
45 | -parameters
46 | -parameters
47 | ${java.version}
48 | ${java.version}
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/first-service/src/main/java/com/rmz/first/FirstApplication.java:
--------------------------------------------------------------------------------
1 | package com.rmz.first;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class FirstApplication {
8 | public static void main(String[] args) {
9 | SpringApplication.run(FirstApplication.class, args);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/first-service/src/main/java/com/rmz/first/backendRunner/CustomizationBean.java:
--------------------------------------------------------------------------------
1 | package com.rmz.first.backendRunner;
2 |
3 | import org.springframework.beans.factory.annotation.Value;
4 | import org.springframework.boot.web.server.WebServerFactoryCustomizer;
5 | import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
6 |
7 | public class CustomizationBean implements WebServerFactoryCustomizer{
8 |
9 | @Value( "${backend.apps.first.contextPath}" )
10 | private String contextPath;
11 |
12 | @Value( "${backend.apps.first.port}" )
13 | private Integer port;
14 |
15 | @Override
16 | public void customize(ConfigurableServletWebServerFactory factory) {
17 | factory.setContextPath(contextPath);
18 | factory.setPort(port);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/first-service/src/main/java/com/rmz/first/backendRunner/FirstServiceBackendRunner.java:
--------------------------------------------------------------------------------
1 | package com.rmz.first.backendRunner;
2 |
3 | import com.rmz.common.BackendRunner;
4 | import com.rmz.first.FirstApplication;
5 |
6 | public class FirstServiceBackendRunner extends BackendRunner{
7 | public FirstServiceBackendRunner() {
8 | super(FirstApplication.class, CustomizationBean.class);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/first-service/src/main/java/com/rmz/first/config/SwaggerConfig.java:
--------------------------------------------------------------------------------
1 | package com.rmz.first.config;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | import springfox.documentation.builders.PathSelectors;
7 | import springfox.documentation.builders.RequestHandlerSelectors;
8 | import springfox.documentation.spi.DocumentationType;
9 | import springfox.documentation.spring.web.plugins.Docket;
10 | import springfox.documentation.swagger2.annotations.EnableSwagger2;
11 |
12 | @Configuration
13 | @EnableSwagger2
14 | public class SwaggerConfig {
15 |
16 | @Bean
17 | public Docket api() {
18 | return new Docket(DocumentationType.SWAGGER_2).select().apis(
19 | RequestHandlerSelectors.any()).paths(PathSelectors.any()).build();
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/first-service/src/main/java/com/rmz/first/controller/FirstController.java:
--------------------------------------------------------------------------------
1 | package com.rmz.first.controller;
2 |
3 | import org.springframework.web.bind.annotation.RequestMapping;
4 | import org.springframework.web.bind.annotation.RequestMethod;
5 | import org.springframework.web.bind.annotation.RestController;
6 |
7 | @RestController
8 | public class FirstController {
9 |
10 | @RequestMapping(value = "/index", method = RequestMethod.GET)
11 | public String index() throws Exception {
12 | return "Hello from first microservice!";
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/first-service/src/main/resources/application-dev.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8110
3 | servlet:
4 | contextPath: /first
--------------------------------------------------------------------------------
/springboot-distribution-assembly/first-service/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | # config context path to "/" by setting an empty string
2 | spring:
3 | application:
4 | name: FirstService
5 | profiles:
6 | active: dev
--------------------------------------------------------------------------------
/springboot-distribution-assembly/first-service/src/test/java/com/rmz/first/AppTest.java:
--------------------------------------------------------------------------------
1 | package com.rmz.first;
2 |
3 | import junit.framework.Test;
4 | import junit.framework.TestCase;
5 | import junit.framework.TestSuite;
6 |
7 | /**
8 | * Unit test for simple App.
9 | */
10 | public class AppTest
11 | extends TestCase
12 | {
13 | /**
14 | * Create the test case
15 | *
16 | * @param testName name of the test case
17 | */
18 | public AppTest( String testName )
19 | {
20 | super( testName );
21 | }
22 |
23 | /**
24 | * @return the suite of tests being tested
25 | */
26 | public static Test suite()
27 | {
28 | return new TestSuite( AppTest.class );
29 | }
30 |
31 | /**
32 | * Rigourous Test :-)
33 | */
34 | public void testApp()
35 | {
36 | assertTrue( true );
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/first-service/target/classes/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Implementation-Title: first-service
3 | Implementation-Version: 0.0.1-SNAPSHOT
4 | Built-By: Rameez.shikalgar
5 | Implementation-Vendor-Id: com.rmz
6 | Build-Jdk: 1.8.0_131
7 | Implementation-URL: http://maven.apache.org
8 | Created-By: Maven Integration for Eclipse
9 |
10 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/first-service/target/classes/META-INF/maven/com.rmz/first-service/pom.properties:
--------------------------------------------------------------------------------
1 | #Generated by Maven Integration for Eclipse
2 | #Fri Aug 17 12:50:03 IST 2018
3 | version=0.0.1-SNAPSHOT
4 | groupId=com.rmz
5 | m2e.projectName=first-service
6 | m2e.projectLocation=C\:\\Users\\Rameez.shikalgar\\git\\springboot-demo\\springboot-distribution-assembly\\first-service
7 | artifactId=first-service
8 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/first-service/target/classes/META-INF/maven/com.rmz/first-service/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.rmz
8 | springboot-distribution-assembly
9 | 0.0.1-SNAPSHOT
10 |
11 | first-service
12 | first-service
13 | http://maven.apache.org
14 |
15 | UTF-8
16 |
17 |
18 |
19 | com.rmz
20 | common-service
21 | ${project.version}
22 |
23 |
24 |
25 |
26 |
27 | org.springframework.boot
28 | spring-boot-maven-plugin
29 |
30 |
31 | org.springframework.boot.experimental
32 | spring-boot-thin-layout
33 | 1.0.3.RELEASE
34 |
35 |
36 |
37 | true
38 |
39 |
40 |
41 | org.apache.maven.plugins
42 | maven-compiler-plugin
43 | 2.3.2
44 |
45 | -parameters
46 | -parameters
47 | ${java.version}
48 | ${java.version}
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/first-service/target/classes/application-dev.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8110
3 | servlet:
4 | contextPath: /first
--------------------------------------------------------------------------------
/springboot-distribution-assembly/first-service/target/classes/application.yml:
--------------------------------------------------------------------------------
1 | # config context path to "/" by setting an empty string
2 | spring:
3 | application:
4 | name: FirstService
5 | profiles:
6 | active: dev
--------------------------------------------------------------------------------
/springboot-distribution-assembly/launcher/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/launcher/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | launcher
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.wst.common.project.facet.core.builder
10 |
11 |
12 |
13 |
14 | org.eclipse.jdt.core.javabuilder
15 |
16 |
17 |
18 |
19 | org.springframework.ide.eclipse.core.springbuilder
20 |
21 |
22 |
23 |
24 | org.springframework.ide.eclipse.boot.validation.springbootbuilder
25 |
26 |
27 |
28 |
29 | org.eclipse.m2e.core.maven2Builder
30 |
31 |
32 |
33 |
34 |
35 | org.springframework.ide.eclipse.core.springnature
36 | org.eclipse.jdt.core.javanature
37 | org.eclipse.m2e.core.maven2Nature
38 | org.eclipse.wst.common.project.facet.core.nature
39 |
40 |
41 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/launcher/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//src/main/java=UTF-8
3 | encoding//src/main/resources=UTF-8
4 | encoding//src/test/java=UTF-8
5 | encoding/=UTF-8
6 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/launcher/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
3 | org.eclipse.jdt.core.compiler.compliance=1.8
4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5 | org.eclipse.jdt.core.compiler.source=1.8
6 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/launcher/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | activeProfiles=
2 | eclipse.preferences.version=1
3 | resolveWorkspaceProjects=true
4 | version=1
5 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/launcher/.settings/org.eclipse.wst.common.project.facet.core.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/launcher/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.rmz
8 | springboot-distribution-assembly
9 | 0.0.1-SNAPSHOT
10 |
11 | launcher
12 | launcher
13 | http://maven.apache.org
14 |
15 | UTF-8
16 |
17 |
18 |
19 | com.rmz
20 | common-service
21 | ${project.version}
22 |
23 |
24 | com.rmz
25 | first-service
26 | ${project.version}
27 |
28 |
29 | com.rmz
30 | second-service
31 | ${project.version}
32 |
33 |
34 |
35 |
36 |
37 | org.codehaus.mojo
38 | exec-maven-plugin
39 | 1.6.0
40 |
41 | com.rmz.launcher.LauncherApplication
42 |
43 |
44 |
45 | org.springframework.boot
46 | spring-boot-maven-plugin
47 |
48 |
49 | org.springframework.boot.experimental
50 | spring-boot-thin-layout
51 | 1.0.3.RELEASE
52 |
53 |
54 |
55 | true
56 |
57 |
58 |
59 | org.apache.maven.plugins
60 | maven-compiler-plugin
61 | 2.3.2
62 |
63 | -parameters
64 | -parameters
65 | ${java.version}
66 | ${java.version}
67 |
68 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/launcher/src/main/java/com/rmz/launcher/LauncherApplication.java:
--------------------------------------------------------------------------------
1 | package com.rmz.launcher;
2 |
3 | public class LauncherApplication {
4 | public static void main(String[] args) {
5 | try {
6 | MicroservicesStarter.startBackends();
7 | } catch (Exception e) {
8 | // TODO Auto-generated catch block
9 | e.printStackTrace();
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/launcher/src/main/java/com/rmz/launcher/MicroservicesStarter.java:
--------------------------------------------------------------------------------
1 | package com.rmz.launcher;
2 |
3 | import java.io.File;
4 | import java.lang.reflect.InvocationTargetException;
5 | import java.net.URL;
6 | import java.net.URLClassLoader;
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | public class MicroservicesStarter {
11 | private static final List activeBackends = new ArrayList<>();
12 |
13 | public MicroservicesStarter() {
14 | }
15 |
16 | public static void startBackends() throws Exception {
17 |
18 | startBackend("first-service", "com.rmz.first.backendRunner.FirstServiceBackendRunner");
19 | startBackend("second-service", "com.rmz.second.backendRunner.SecondServiceBackendRunner");
20 | }
21 |
22 | private static void startBackend(final String backendProjectName, final String backendClassName) throws Exception {
23 | //URL backendRunnerUrl = new File("../YagnaCommonRest/target/classes").toURI().toURL();
24 | URL runnerUrl = new File("../" + backendProjectName + "/target/classes").toURI().toURL();
25 |
26 | URL[] urls = new URL[] { runnerUrl };
27 |
28 | URLClassLoader cl = new URLClassLoader(urls, MicroservicesStarter.class.getClassLoader());
29 | Class> runnerClass = cl.loadClass(backendClassName);
30 |
31 | Object runnerInstance = runnerClass.newInstance();
32 |
33 | final Backend backend = new Backend(runnerClass, runnerInstance);
34 | activeBackends.add(backend);
35 |
36 | runnerClass.getMethod("run").invoke(runnerInstance);
37 | }
38 |
39 | public static void stopAllBackends()
40 | throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
41 | for (Backend b : activeBackends) {
42 | b.runnerClass.getMethod("stop").invoke(b.runnerInstance);
43 | }
44 | }
45 |
46 | private static class Backend {
47 | private Class> runnerClass;
48 | private Object runnerInstance;
49 |
50 | public Backend(final Class> runnerClass, final Object runnerInstance) {
51 | this.runnerClass = runnerClass;
52 | this.runnerInstance = runnerInstance;
53 | }
54 | }
55 | }
--------------------------------------------------------------------------------
/springboot-distribution-assembly/launcher/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: Launcher
4 |
5 | backend:
6 | apps:
7 | first:
8 | contextPath: /first
9 | port: 8110
10 | second:
11 | contextPath: /second
12 | port: 8111
--------------------------------------------------------------------------------
/springboot-distribution-assembly/launcher/src/test/java/com/rmz/launcher/AppTest.java:
--------------------------------------------------------------------------------
1 | package com.rmz.launcher;
2 |
3 | import junit.framework.Test;
4 | import junit.framework.TestCase;
5 | import junit.framework.TestSuite;
6 |
7 | /**
8 | * Unit test for simple App.
9 | */
10 | public class AppTest
11 | extends TestCase
12 | {
13 | /**
14 | * Create the test case
15 | *
16 | * @param testName name of the test case
17 | */
18 | public AppTest( String testName )
19 | {
20 | super( testName );
21 | }
22 |
23 | /**
24 | * @return the suite of tests being tested
25 | */
26 | public static Test suite()
27 | {
28 | return new TestSuite( AppTest.class );
29 | }
30 |
31 | /**
32 | * Rigourous Test :-)
33 | */
34 | public void testApp()
35 | {
36 | assertTrue( true );
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/launcher/target/classes/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Implementation-Title: launcher
3 | Implementation-Version: 0.0.1-SNAPSHOT
4 | Built-By: Rameez.shikalgar
5 | Implementation-Vendor-Id: com.rmz
6 | Build-Jdk: 1.8.0_131
7 | Implementation-URL: http://maven.apache.org
8 | Created-By: Maven Integration for Eclipse
9 |
10 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/launcher/target/classes/META-INF/maven/com.rmz/launcher/pom.properties:
--------------------------------------------------------------------------------
1 | #Generated by Maven Integration for Eclipse
2 | #Fri Aug 17 12:50:03 IST 2018
3 | version=0.0.1-SNAPSHOT
4 | groupId=com.rmz
5 | m2e.projectName=launcher
6 | m2e.projectLocation=C\:\\Users\\Rameez.shikalgar\\git\\springboot-demo\\springboot-distribution-assembly\\launcher
7 | artifactId=launcher
8 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/launcher/target/classes/META-INF/maven/com.rmz/launcher/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.rmz
8 | springboot-distribution-assembly
9 | 0.0.1-SNAPSHOT
10 |
11 | launcher
12 | launcher
13 | http://maven.apache.org
14 |
15 | UTF-8
16 |
17 |
18 |
19 | com.rmz
20 | common-service
21 | ${project.version}
22 |
23 |
24 | com.rmz
25 | first-service
26 | ${project.version}
27 |
28 |
29 | com.rmz
30 | second-service
31 | ${project.version}
32 |
33 |
34 |
35 |
36 |
37 | org.codehaus.mojo
38 | exec-maven-plugin
39 | 1.6.0
40 |
41 | com.rmz.launcher.LauncherApplication
42 |
43 |
44 |
45 | org.springframework.boot
46 | spring-boot-maven-plugin
47 |
48 |
49 | org.springframework.boot.experimental
50 | spring-boot-thin-layout
51 | 1.0.3.RELEASE
52 |
53 |
54 |
55 | true
56 |
57 |
58 |
59 | org.apache.maven.plugins
60 | maven-compiler-plugin
61 | 2.3.2
62 |
63 | -parameters
64 | -parameters
65 | ${java.version}
66 | ${java.version}
67 |
68 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/launcher/target/classes/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: Launcher
4 |
5 | backend:
6 | apps:
7 | first:
8 | contextPath: /first
9 | port: 8110
10 | second:
11 | contextPath: /second
12 | port: 8111
--------------------------------------------------------------------------------
/springboot-distribution-assembly/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.rmz
7 | springboot-distribution-assembly
8 | 0.0.1-SNAPSHOT
9 | pom
10 |
11 | springboot-multi-service-launcher
12 | Demo project for launching multiple microservices with one jvm
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 2.0.4.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | UTF-8
24 | 1.8
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter-web
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-test
36 | test
37 |
38 |
39 |
40 |
41 | io.springfox
42 | springfox-swagger2
43 | 2.9.2
44 |
45 |
46 |
47 | io.springfox
48 | springfox-swagger-ui
49 | 2.9.1
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | org.springframework.boot
59 | spring-boot-maven-plugin
60 |
61 |
62 |
63 |
64 |
65 |
66 | common-service
67 | first-service
68 | second-service
69 | launcher
70 | distribution
71 |
72 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/second-service/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/second-service/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | second-service
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.wst.common.project.facet.core.builder
10 |
11 |
12 |
13 |
14 | org.eclipse.jdt.core.javabuilder
15 |
16 |
17 |
18 |
19 | org.springframework.ide.eclipse.core.springbuilder
20 |
21 |
22 |
23 |
24 | org.springframework.ide.eclipse.boot.validation.springbootbuilder
25 |
26 |
27 |
28 |
29 | org.eclipse.m2e.core.maven2Builder
30 |
31 |
32 |
33 |
34 |
35 | org.springframework.ide.eclipse.core.springnature
36 | org.eclipse.jdt.core.javanature
37 | org.eclipse.m2e.core.maven2Nature
38 | org.eclipse.wst.common.project.facet.core.nature
39 |
40 |
41 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/second-service/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//src/main/java=UTF-8
3 | encoding//src/main/resources=UTF-8
4 | encoding//src/test/java=UTF-8
5 | encoding/=UTF-8
6 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/second-service/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
3 | org.eclipse.jdt.core.compiler.compliance=1.8
4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5 | org.eclipse.jdt.core.compiler.source=1.8
6 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/second-service/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | activeProfiles=
2 | eclipse.preferences.version=1
3 | resolveWorkspaceProjects=true
4 | version=1
5 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/second-service/.settings/org.eclipse.wst.common.project.facet.core.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/second-service/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.rmz
8 | springboot-distribution-assembly
9 | 0.0.1-SNAPSHOT
10 |
11 | second-service
12 | second-service
13 | http://maven.apache.org
14 |
15 | UTF-8
16 |
17 |
18 |
19 | com.rmz
20 | common-service
21 | ${project.version}
22 |
23 |
24 |
25 |
26 |
27 | org.springframework.boot
28 | spring-boot-maven-plugin
29 |
30 |
31 | org.springframework.boot.experimental
32 | spring-boot-thin-layout
33 | 1.0.3.RELEASE
34 |
35 |
36 |
37 | true
38 |
39 |
40 |
41 | org.apache.maven.plugins
42 | maven-compiler-plugin
43 | 2.3.2
44 |
45 | -parameters
46 | -parameters
47 | ${java.version}
48 | ${java.version}
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/second-service/src/main/java/com/rmz/second/SecondApplication.java:
--------------------------------------------------------------------------------
1 | package com.rmz.second;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SecondApplication {
8 | public static void main(String[] args) {
9 | SpringApplication.run(SecondApplication.class, args);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/second-service/src/main/java/com/rmz/second/backendRunner/CustomizationBean.java:
--------------------------------------------------------------------------------
1 | package com.rmz.second.backendRunner;
2 |
3 | import org.springframework.beans.factory.annotation.Value;
4 | import org.springframework.boot.web.server.WebServerFactoryCustomizer;
5 | import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
6 |
7 | public class CustomizationBean implements WebServerFactoryCustomizer{
8 |
9 | @Value( "${backend.apps.second.contextPath}" )
10 | private String contextPath;
11 |
12 | @Value( "${backend.apps.second.port}" )
13 | private Integer port;
14 |
15 | @Override
16 | public void customize(ConfigurableServletWebServerFactory factory) {
17 | factory.setContextPath(contextPath);
18 | factory.setPort(port);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/second-service/src/main/java/com/rmz/second/backendRunner/SecondServiceBackendRunner.java:
--------------------------------------------------------------------------------
1 | package com.rmz.second.backendRunner;
2 |
3 | import com.rmz.common.BackendRunner;
4 | import com.rmz.second.SecondApplication;
5 |
6 | public class SecondServiceBackendRunner extends BackendRunner{
7 | public SecondServiceBackendRunner() {
8 | super(SecondApplication.class, CustomizationBean.class);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/second-service/src/main/java/com/rmz/second/config/SwaggerConfig.java:
--------------------------------------------------------------------------------
1 | package com.rmz.second.config;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | import springfox.documentation.builders.PathSelectors;
7 | import springfox.documentation.builders.RequestHandlerSelectors;
8 | import springfox.documentation.spi.DocumentationType;
9 | import springfox.documentation.spring.web.plugins.Docket;
10 | import springfox.documentation.swagger2.annotations.EnableSwagger2;
11 |
12 | @Configuration
13 | @EnableSwagger2
14 | public class SwaggerConfig {
15 |
16 | @Bean
17 | public Docket api() {
18 | return new Docket(DocumentationType.SWAGGER_2).select().apis(
19 | RequestHandlerSelectors.any()).paths(PathSelectors.any()).build();
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/second-service/src/main/java/com/rmz/second/controller/SecondController.java:
--------------------------------------------------------------------------------
1 | package com.rmz.second.controller;
2 |
3 | import org.springframework.web.bind.annotation.RequestMapping;
4 | import org.springframework.web.bind.annotation.RequestMethod;
5 | import org.springframework.web.bind.annotation.RestController;
6 |
7 | @RestController
8 | public class SecondController {
9 |
10 | @RequestMapping(value = "/index", method = RequestMethod.GET)
11 | public String index() throws Exception {
12 | return "Hello from second microservice!";
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/second-service/src/main/resources/application-dev.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8111
3 | servlet:
4 | contextPath: /second
--------------------------------------------------------------------------------
/springboot-distribution-assembly/second-service/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | # config context path to "/" by setting an empty string
2 | spring:
3 | application:
4 | name: SecondService
5 | profiles:
6 | active: dev
--------------------------------------------------------------------------------
/springboot-distribution-assembly/second-service/src/test/java/com/rmz/second/AppTest.java:
--------------------------------------------------------------------------------
1 | package com.rmz.second;
2 |
3 | import junit.framework.Test;
4 | import junit.framework.TestCase;
5 | import junit.framework.TestSuite;
6 |
7 | /**
8 | * Unit test for simple App.
9 | */
10 | public class AppTest
11 | extends TestCase
12 | {
13 | /**
14 | * Create the test case
15 | *
16 | * @param testName name of the test case
17 | */
18 | public AppTest( String testName )
19 | {
20 | super( testName );
21 | }
22 |
23 | /**
24 | * @return the suite of tests being tested
25 | */
26 | public static Test suite()
27 | {
28 | return new TestSuite( AppTest.class );
29 | }
30 |
31 | /**
32 | * Rigourous Test :-)
33 | */
34 | public void testApp()
35 | {
36 | assertTrue( true );
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/second-service/target/classes/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Implementation-Title: second-service
3 | Implementation-Version: 0.0.1-SNAPSHOT
4 | Built-By: Rameez.shikalgar
5 | Implementation-Vendor-Id: com.rmz
6 | Build-Jdk: 1.8.0_131
7 | Implementation-URL: http://maven.apache.org
8 | Created-By: Maven Integration for Eclipse
9 |
10 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/second-service/target/classes/META-INF/maven/com.rmz/second-service/pom.properties:
--------------------------------------------------------------------------------
1 | #Generated by Maven Integration for Eclipse
2 | #Fri Aug 17 12:50:03 IST 2018
3 | version=0.0.1-SNAPSHOT
4 | groupId=com.rmz
5 | m2e.projectName=second-service
6 | m2e.projectLocation=C\:\\Users\\Rameez.shikalgar\\git\\springboot-demo\\springboot-distribution-assembly\\second-service
7 | artifactId=second-service
8 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/second-service/target/classes/META-INF/maven/com.rmz/second-service/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.rmz
8 | springboot-distribution-assembly
9 | 0.0.1-SNAPSHOT
10 |
11 | second-service
12 | second-service
13 | http://maven.apache.org
14 |
15 | UTF-8
16 |
17 |
18 |
19 | com.rmz
20 | common-service
21 | ${project.version}
22 |
23 |
24 |
25 |
26 |
27 | org.springframework.boot
28 | spring-boot-maven-plugin
29 |
30 |
31 | org.springframework.boot.experimental
32 | spring-boot-thin-layout
33 | 1.0.3.RELEASE
34 |
35 |
36 |
37 | true
38 |
39 |
40 |
41 | org.apache.maven.plugins
42 | maven-compiler-plugin
43 | 2.3.2
44 |
45 | -parameters
46 | -parameters
47 | ${java.version}
48 | ${java.version}
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/springboot-distribution-assembly/second-service/target/classes/application-dev.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8111
3 | servlet:
4 | contextPath: /second
--------------------------------------------------------------------------------
/springboot-distribution-assembly/second-service/target/classes/application.yml:
--------------------------------------------------------------------------------
1 | # config context path to "/" by setting an empty string
2 | spring:
3 | application:
4 | name: SecondService
5 | profiles:
6 | active: dev
--------------------------------------------------------------------------------
/springboot-json-crud/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/springboot-json-crud/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | springboot-json-crud
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.wst.common.project.facet.core.builder
10 |
11 |
12 |
13 |
14 | org.eclipse.jdt.core.javabuilder
15 |
16 |
17 |
18 |
19 | org.springframework.ide.eclipse.core.springbuilder
20 |
21 |
22 |
23 |
24 | org.springframework.ide.eclipse.boot.validation.springbootbuilder
25 |
26 |
27 |
28 |
29 | org.eclipse.m2e.core.maven2Builder
30 |
31 |
32 |
33 |
34 |
35 | org.springframework.ide.eclipse.core.springnature
36 | org.eclipse.jdt.core.javanature
37 | org.eclipse.m2e.core.maven2Nature
38 | org.eclipse.wst.common.project.facet.core.nature
39 |
40 |
41 |
--------------------------------------------------------------------------------
/springboot-json-crud/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//src/main/java=UTF-8
3 | encoding//src/main/resources=UTF-8
4 | encoding/=UTF-8
5 |
--------------------------------------------------------------------------------
/springboot-json-crud/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
3 | org.eclipse.jdt.core.compiler.compliance=1.8
4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5 | org.eclipse.jdt.core.compiler.source=1.8
6 |
--------------------------------------------------------------------------------
/springboot-json-crud/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | activeProfiles=
2 | eclipse.preferences.version=1
3 | resolveWorkspaceProjects=true
4 | version=1
5 |
--------------------------------------------------------------------------------
/springboot-json-crud/.settings/org.eclipse.wst.common.project.facet.core.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/springboot-json-crud/.springBeans:
--------------------------------------------------------------------------------
1 |
2 |
3 | 1
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/springboot-json-crud/DEVELOPMENT.md:
--------------------------------------------------------------------------------
1 | Prerequisite: Java8, Maven3+, eclipse with JDK 8 compatibility.
2 |
3 | Here are some basic details about technologies used.
4 |
5 | 1) Spring Boot 2.0.4.RELEASE
6 | 2) org.projectlombok -- To dynamically create getter setters and constructors. If you don't put lombak.jar at eclipse home it will give warnings in eclipse.
7 | 3) com.fasterxml.jackson and org.json to process JSONs.
8 | 4) springfox-swagger2 -- For API documentation.
9 | 5) spring-boot-starter-actuator -- Helpful to monitor service.
10 | 6) com.h2database -- To use JPA beauty for filtering and sorting data using Spring Specification framework used in-memory h2 database.
--------------------------------------------------------------------------------
/springboot-json-crud/README:
--------------------------------------------------------------------------------
1 | Prerequisite: Java8, Maven3+
2 |
3 | This is demo project to illustrate CRUD operations on JSON file.
4 |
5 | Follow below steps to start the service
6 |
7 | 1) $ git clone https://github.com/rameez4ever/springboot-demo.git
8 | 2) $ cd springboot-json-crud
9 | 2) $ mvn clean install
10 | 3) $ mvn spring-boot:run
11 | 4) This will launch microservice. You can use swagger doc to find documentation for all rest APIs:
12 | http://localhost:8110/cabaran/swagger-ui.html
13 |
14 | ***Updating configuration***
15 | 1) You can update server configuration and json file configuration @application-{profile}.yml file.
16 | 2) By default dev profile is active.
17 |
18 | ***CRUD endpoints***
19 | ----------------
20 | 1) http://localhost:8110/cabaran/api/v1/employee/get -- GET
21 | 2) http://localhost:8110/cabaran/api/v1/employee/create -- POST
22 | 3) http://localhost:8110/cabaran/api/v1/employee/create -- PATCH
23 | 4) http://localhost:8110/cabaran/api/v1/employee/delete -- DELETE
24 |
25 | ***Filtering endpoints example***
26 | --------------------
27 | 1) http://localhost:8110/cabaran/api/v1/employee/filterByAge?operator=lt&value=20 -- GET
28 | 2) http://localhost:8110/cabaran/api/v1/employee/get?key=salary&operator=lte&value=20&sort=asc -- GET
29 |
30 | Please visit swagger documentation for API signatures.
31 |
32 | ***Refresh cache***
33 | ---------------
34 | 1) We are caching the employee data on application start up. So if any updates to json then that should be done from application only.
35 | 2) If json file is updated manually then please refresh the cache by hitting below endpoint.
36 |
37 | http://localhost:8110/cabaran/api/v1/employee/refresh
38 |
39 | ***Monitoring endpoints***
40 | ----------------------
41 | Once started you will get number of endpoints available for you for monitoring purpose
42 | http://localhost:8110/cabaran/swagger-ui.html#/operation-handler
43 |
44 | ***Internationalization***
45 | To change the locale to Malaysia just add 'lang' parameter to any request.
46 | e.g http://localhost:8110/cabaran/api/v1/employee/create?lang=my
47 |
48 | ***Future Scope***
49 | 1) Spring Security + OAuth 2.0 for securing endpoints.
50 |
--------------------------------------------------------------------------------
/springboot-json-crud/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.rmz
7 | springboot-json-crud
8 | 0.0.1-SNAPSHOT
9 | jar
10 |
11 | springboot-json-crud
12 | Spring Boot demo project to illustrate CRUD operations on JSON file structure
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 2.0.4.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | UTF-8
24 | 1.8
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter-web
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-data-jpa
36 |
37 |
38 |
39 | org.springframework.boot
40 | spring-boot-starter-actuator
41 |
42 |
43 |
44 | org.springframework.boot
45 | spring-boot-starter-test
46 | test
47 |
48 |
49 |
50 | com.h2database
51 | h2
52 | runtime
53 |
54 |
55 |
56 |
57 | org.json
58 | json
59 | 20180813
60 |
61 |
62 |
63 |
64 | org.projectlombok
65 | lombok
66 |
67 |
68 |
69 |
70 | io.springfox
71 | springfox-swagger2
72 | 2.9.2
73 |
74 |
75 |
76 | io.springfox
77 | springfox-swagger-ui
78 | 2.9.1
79 |
80 |
81 |
82 | org.apache.commons
83 | commons-lang3
84 | 3.6
85 |
86 |
87 |
88 |
89 |
90 | spring-releases
91 | https://repo.spring.io/libs-release
92 |
93 |
94 |
95 |
96 | spring-releases
97 | https://repo.spring.io/libs-release
98 |
99 |
100 |
101 |
102 |
103 |
104 | org.springframework.boot
105 | spring-boot-maven-plugin
106 |
107 |
108 |
109 |
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/java/com/raydar/CabaranApplication.java:
--------------------------------------------------------------------------------
1 | package com.raydar;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class CabaranApplication {
8 | public static void main(String[] args) {
9 | SpringApplication.run(CabaranApplication.class, args);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/java/com/raydar/config/AppConfig.java:
--------------------------------------------------------------------------------
1 | package com.raydar.config;
2 |
3 | import java.io.File;
4 | import java.io.IOException;
5 | import java.util.ArrayList;
6 | import java.util.List;
7 | import java.util.Locale;
8 |
9 | import javax.annotation.PostConstruct;
10 |
11 | import org.springframework.beans.factory.annotation.Autowired;
12 | import org.springframework.cache.CacheManager;
13 | import org.springframework.cache.annotation.EnableCaching;
14 | import org.springframework.cache.concurrent.ConcurrentMapCache;
15 | import org.springframework.cache.support.SimpleCacheManager;
16 | import org.springframework.context.annotation.Bean;
17 | import org.springframework.context.annotation.ComponentScan;
18 | import org.springframework.context.annotation.Configuration;
19 | import org.springframework.core.env.Environment;
20 | import org.springframework.web.servlet.LocaleResolver;
21 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
22 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
23 | import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
24 | import org.springframework.web.servlet.i18n.SessionLocaleResolver;
25 |
26 | /**
27 | * @author Rameez.shikalgar
28 | *
29 | */
30 | @ComponentScan
31 | @EnableCaching
32 | @Configuration
33 | public class AppConfig implements WebMvcConfigurer{
34 |
35 | @Autowired
36 | private Environment environment;
37 |
38 |
39 | /**
40 | * @throws IOException
41 | * This will make sure to create JSON database as configured in properties to be present.
42 | */
43 | @PostConstruct
44 | public void init() throws IOException{
45 | File file = file();
46 | file.getParentFile().mkdirs();
47 | file.createNewFile();
48 | }
49 |
50 | /**
51 | * @return
52 | * @throws IOException
53 | */
54 | @Bean
55 | public File file() throws IOException{
56 | File file = new File(environment.getProperty("app.filedir") + "/" + environment.getProperty("app.filename"));
57 | return file;
58 | }
59 |
60 | /**
61 | * @return
62 | * Holds cache for application
63 | */
64 | @Bean
65 | public CacheManager cacheManager() {
66 | SimpleCacheManager cacheManager = new SimpleCacheManager();
67 |
68 | ConcurrentMapCache employeeMap = new ConcurrentMapCache("employeeMap");
69 | List cacheList = new ArrayList();
70 | cacheList.add(employeeMap);
71 | cacheManager.setCaches(cacheList);
72 | return cacheManager;
73 | }
74 |
75 | @Bean
76 | public LocaleResolver localeResolver() {
77 | SessionLocaleResolver slr = new SessionLocaleResolver();
78 | slr.setDefaultLocale(Locale.US);
79 | return slr;
80 | }
81 |
82 | @Bean
83 | public LocaleChangeInterceptor localeChangeInterceptor() {
84 | LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
85 | lci.setParamName("lang");
86 | return lci;
87 | }
88 |
89 | @Override
90 | public void addInterceptors(InterceptorRegistry registry) {
91 | registry.addInterceptor(localeChangeInterceptor());
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/java/com/raydar/config/SpringEventsListener.java:
--------------------------------------------------------------------------------
1 | package com.raydar.config;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.context.event.ContextRefreshedEvent;
5 | import org.springframework.context.event.EventListener;
6 | import org.springframework.stereotype.Component;
7 |
8 | import com.raydar.service.ICacheService;
9 |
10 | @Component
11 | public class SpringEventsListener {
12 |
13 | @Autowired
14 | ICacheService cacheService;
15 |
16 | @EventListener
17 | public void onApplicationReady(ContextRefreshedEvent event) throws Exception {
18 | cacheService.getEmployeeMap();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/java/com/raydar/config/SwaggerConfig.java:
--------------------------------------------------------------------------------
1 | package com.raydar.config;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | import springfox.documentation.builders.PathSelectors;
7 | import springfox.documentation.builders.RequestHandlerSelectors;
8 | import springfox.documentation.spi.DocumentationType;
9 | import springfox.documentation.spring.web.plugins.Docket;
10 | import springfox.documentation.swagger2.annotations.EnableSwagger2;
11 |
12 | @Configuration
13 | @EnableSwagger2
14 | public class SwaggerConfig {
15 |
16 | @Bean
17 | public Docket api() {
18 | return new Docket(DocumentationType.SWAGGER_2).select().apis(
19 | RequestHandlerSelectors.any()).paths(PathSelectors.any()).build();
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/java/com/raydar/controller/CabaranController.java:
--------------------------------------------------------------------------------
1 | package com.raydar.controller;
2 |
3 | import org.springframework.web.bind.annotation.RequestMapping;
4 | import org.springframework.web.bind.annotation.RequestMethod;
5 | import org.springframework.web.bind.annotation.RestController;
6 |
7 | @RestController
8 | public class CabaranController {
9 |
10 | @RequestMapping(value = {"/", "/index"}, method = RequestMethod.GET)
11 | public String index() throws Exception {
12 | return "Hello from Cabaran Microservice!";
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/java/com/raydar/controller/EmployeeController.java:
--------------------------------------------------------------------------------
1 | package com.raydar.controller;
2 |
3 | import javax.validation.Valid;
4 |
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.validation.Errors;
7 | import org.springframework.web.bind.WebDataBinder;
8 | import org.springframework.web.bind.annotation.InitBinder;
9 | import org.springframework.web.bind.annotation.PathVariable;
10 | import org.springframework.web.bind.annotation.RequestBody;
11 | import org.springframework.web.bind.annotation.RequestMapping;
12 | import org.springframework.web.bind.annotation.RequestMethod;
13 | import org.springframework.web.bind.annotation.RestController;
14 |
15 | import com.raydar.dto.EmployeeDTO;
16 | import com.raydar.dto.EmployeeDataResponseDTO;
17 | import com.raydar.filter.SearchCriteria;
18 | import com.raydar.service.IEmployeeService;
19 | import com.raydar.validator.EmployeeValidator;
20 |
21 | @RestController
22 | @RequestMapping("/api/v1/employee")
23 | public class EmployeeController {
24 |
25 | @Autowired
26 | private IEmployeeService employeeService;
27 |
28 | @InitBinder("employeeDTO")
29 | protected void initEmployeeBinder(WebDataBinder binder) {
30 | binder.addValidators(new EmployeeValidator());
31 | }
32 |
33 | @RequestMapping(value = {"/"}, method = RequestMethod.GET)
34 | public String index() throws Exception {
35 | return "Hello from Cabaran Microservice!";
36 | }
37 |
38 | @RequestMapping(value = {"/get"}, method = RequestMethod.GET)
39 | public EmployeeDataResponseDTO get(SearchCriteria criteria) throws Exception{
40 | return employeeService.get(criteria);
41 | }
42 |
43 | @RequestMapping(value = {"/create"}, method = RequestMethod.POST)
44 | public EmployeeDataResponseDTO save(@Valid @RequestBody EmployeeDTO employeeDTO) throws Exception{
45 | return employeeService.save(employeeDTO);
46 | }
47 |
48 | @RequestMapping(value = {"/update"}, method = RequestMethod.PATCH)
49 | public EmployeeDataResponseDTO update(@Valid @RequestBody EmployeeDTO employeeDTO) throws Exception{
50 | return employeeService.update(employeeDTO);
51 | }
52 |
53 | @RequestMapping(value = {"/delete/{id}"}, method = RequestMethod.DELETE)
54 | public EmployeeDataResponseDTO delete(@PathVariable Long id) throws Exception{
55 | return employeeService.delete(id);
56 | }
57 |
58 | @RequestMapping(value = {"/filterByAge"}, method = RequestMethod.GET)
59 | public EmployeeDataResponseDTO filterByAge(SearchCriteria criteria) throws Exception{
60 | return employeeService.filterByAge(criteria);
61 | }
62 |
63 | @RequestMapping(value = {"/refresh"}, method = RequestMethod.GET)
64 | public void refreshCache() throws Exception{
65 | employeeService.refreshCache();
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/java/com/raydar/domain/Employee.java:
--------------------------------------------------------------------------------
1 | package com.raydar.domain;
2 |
3 | import java.io.Serializable;
4 |
5 | import javax.persistence.Column;
6 | import javax.persistence.Entity;
7 | import javax.persistence.GeneratedValue;
8 | import javax.persistence.Id;
9 | import javax.persistence.Table;
10 |
11 | import lombok.AllArgsConstructor;
12 | import lombok.Data;
13 |
14 | @Data
15 | @AllArgsConstructor
16 | @Entity
17 | @Table(name = "employee")
18 | public class Employee implements Serializable{
19 |
20 | /**
21 | *
22 | */
23 | private static final long serialVersionUID = 1L;
24 |
25 | @Id
26 | private Long id;
27 | private String fullName;
28 | private Integer age;
29 | private Double salary;
30 |
31 | public Employee(){
32 |
33 | }
34 |
35 | public Employee(Long id) {
36 | this.id = id;
37 | }
38 |
39 | @Override
40 | public String toString() {
41 | return "Employee{" + "id=" + id + ", fullName='" + fullName + '\'' + ", age='" + age + '\'' + ", salary='"
42 | + salary + '\'' + '}';
43 | }
44 |
45 | @Override
46 | public int hashCode() {
47 | final int prime = 31;
48 | int result = 1;
49 | result = prime * result + ((id == null) ? 0 : id.hashCode());
50 | return result;
51 | }
52 |
53 | @Override
54 | public boolean equals(Object obj) {
55 | if (this == obj)
56 | return true;
57 | if (obj == null)
58 | return false;
59 | if (getClass() != obj.getClass())
60 | return false;
61 | Employee other = (Employee) obj;
62 | if (id == null) {
63 | if (other.id != null)
64 | return false;
65 | } else if (!id.equals(other.id))
66 | return false;
67 | return true;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/java/com/raydar/dto/BaseResponseDTO.java:
--------------------------------------------------------------------------------
1 | package com.raydar.dto;
2 |
3 | import java.io.Serializable;
4 |
5 | import com.fasterxml.jackson.annotation.JsonInclude;
6 |
7 | import lombok.AllArgsConstructor;
8 | import lombok.Data;
9 |
10 | /**
11 | * @author Rameez.shikalgar
12 | * BaseResponseDTO.java - This will add generic data like status, error codes, messages to
13 | */
14 | @Data
15 | @AllArgsConstructor
16 | public class BaseResponseDTO implements Serializable{
17 |
18 | /**
19 | *
20 | */
21 | private static final long serialVersionUID = 1L;
22 |
23 | private Boolean status;
24 |
25 | @JsonInclude(JsonInclude.Include.NON_NULL)
26 | private Integer error_code;
27 |
28 | @JsonInclude(JsonInclude.Include.NON_NULL)
29 | private String message;
30 |
31 | public BaseResponseDTO(){
32 |
33 | }
34 |
35 | public BaseResponseDTO(Boolean status){
36 | this.status = status;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/java/com/raydar/dto/EmployeeDTO.java:
--------------------------------------------------------------------------------
1 | package com.raydar.dto;
2 |
3 | import java.io.Serializable;
4 |
5 | import lombok.AllArgsConstructor;
6 | import lombok.Data;
7 |
8 | @Data
9 | @AllArgsConstructor
10 | public class EmployeeDTO implements Serializable{
11 |
12 | /**
13 | *
14 | */
15 | private static final long serialVersionUID = 1L;
16 |
17 | private Long id;
18 | private String fullName;
19 | private Integer age;
20 | private Double salary;
21 |
22 | public EmployeeDTO(){
23 |
24 | }
25 |
26 | @Override
27 | public String toString() {
28 | return "Employee{" + "id=" + id + ", fullName='" + fullName + '\'' + ", age='" + age + '\'' + ", salary='"
29 | + salary + '\'' + '}';
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/java/com/raydar/dto/EmployeeDataResponseDTO.java:
--------------------------------------------------------------------------------
1 | package com.raydar.dto;
2 |
3 | import java.io.Serializable;
4 | import java.util.List;
5 |
6 | import com.fasterxml.jackson.annotation.JsonInclude;
7 |
8 | import lombok.AllArgsConstructor;
9 | import lombok.Data;
10 |
11 | /**
12 | * @author Rameez.shikalgar
13 | * EmployeeDataResponseDTO.java - DTO for employee type response.
14 | */
15 | @Data
16 | @AllArgsConstructor
17 | public class EmployeeDataResponseDTO extends BaseResponseDTO implements Serializable{
18 |
19 | /**
20 | *
21 | */
22 | private static final long serialVersionUID = 1L;
23 |
24 | @JsonInclude(JsonInclude.Include.NON_NULL)
25 | private List data;
26 |
27 | public EmployeeDataResponseDTO(){
28 |
29 | }
30 |
31 | public EmployeeDataResponseDTO(Boolean status, List data){
32 | super(status);
33 | this.data = data;
34 | }
35 |
36 | public EmployeeDataResponseDTO(Boolean status, Integer error_code, String error_message){
37 | super(status, error_code, error_message);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/java/com/raydar/exception/CustomizedResponseEntityExceptionHandler.java:
--------------------------------------------------------------------------------
1 | package com.raydar.exception;
2 |
3 | import java.util.Date;
4 |
5 | import org.slf4j.Logger;
6 | import org.slf4j.LoggerFactory;
7 | import org.springframework.http.HttpHeaders;
8 | import org.springframework.http.HttpStatus;
9 | import org.springframework.http.ResponseEntity;
10 | import org.springframework.web.bind.MethodArgumentNotValidException;
11 | import org.springframework.web.bind.annotation.ControllerAdvice;
12 | import org.springframework.web.bind.annotation.ExceptionHandler;
13 | import org.springframework.web.bind.annotation.RestController;
14 | import org.springframework.web.bind.annotation.RestControllerAdvice;
15 | import org.springframework.web.context.request.WebRequest;
16 | import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
17 |
18 | @RestControllerAdvice
19 | public class CustomizedResponseEntityExceptionHandler {
20 |
21 | private static Logger logger = LoggerFactory.getLogger(CustomizedResponseEntityExceptionHandler.class.getName());
22 |
23 | @ExceptionHandler(Exception.class)
24 | public final ResponseEntity handleAllExceptions(Exception ex, WebRequest request) {
25 | logger.error("Internal Server error", ex);
26 | ErrorDetails errorDetails = new ErrorDetails(new Date(), ex.getMessage(), request.getDescription(false));
27 | return new ResponseEntity<>(errorDetails, HttpStatus.INTERNAL_SERVER_ERROR);
28 | }
29 |
30 | @ExceptionHandler(EmployeeNotFoundException.class)
31 | public final ResponseEntity handleEmployeeNotFoundException(EmployeeNotFoundException ex,
32 | WebRequest request) {
33 | ErrorDetails errorDetails = new ErrorDetails(new Date(), ex.getMessage(), request.getDescription(false));
34 | return new ResponseEntity<>(errorDetails, HttpStatus.NOT_FOUND);
35 | }
36 | }
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/java/com/raydar/exception/EmployeeNotFoundException.java:
--------------------------------------------------------------------------------
1 | package com.raydar.exception;
2 |
3 | public class EmployeeNotFoundException extends RuntimeException{
4 |
5 | public EmployeeNotFoundException(String exception){
6 | super(exception);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/java/com/raydar/exception/ErrorDetails.java:
--------------------------------------------------------------------------------
1 | package com.raydar.exception;
2 |
3 | import java.util.Date;
4 |
5 | public class ErrorDetails {
6 | private Date timestamp;
7 | private String message;
8 | private String details;
9 |
10 | public ErrorDetails(Date timestamp, String message, String details) {
11 | super();
12 | this.timestamp = timestamp;
13 | this.message = message;
14 | this.details = details;
15 | }
16 |
17 | public Date getTimestamp() {
18 | return timestamp;
19 | }
20 |
21 | public String getMessage() {
22 | return message;
23 | }
24 |
25 | public String getDetails() {
26 | return details;
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/java/com/raydar/filter/EmployeeSpecification.java:
--------------------------------------------------------------------------------
1 | package com.raydar.filter;
2 |
3 | import javax.persistence.criteria.CriteriaBuilder;
4 | import javax.persistence.criteria.CriteriaQuery;
5 | import javax.persistence.criteria.Predicate;
6 | import javax.persistence.criteria.Root;
7 |
8 | import org.springframework.data.jpa.domain.Specification;
9 |
10 | import com.raydar.domain.Employee;
11 |
12 | /**
13 | * @author Rameez.shikalgar
14 | * EmployeeSpecification- This class will transform
15 | * FilterOperations and SortOperations to actual Hibernate criteria queries to filter and sort records
16 | */
17 | public class EmployeeSpecification implements Specification {
18 |
19 | private SearchCriteria criteria;
20 |
21 | public EmployeeSpecification(SearchCriteria criteria) {
22 | super();
23 | this.criteria = criteria;
24 | }
25 |
26 | @Override
27 | public Predicate toPredicate(Root root, CriteriaQuery> query, CriteriaBuilder builder) {
28 |
29 | if(criteria.getSort() != null){
30 | if(criteria.getSort().equals(SortOperation.asc)){
31 | query.orderBy(builder.asc(root.get(criteria.getKey())));
32 | } else if(criteria.getSort().equals(SortOperation.desc)){
33 | query.orderBy(builder.desc(root.get(criteria.getKey())));
34 | }
35 | }
36 | if(criteria.getOperator() != null){
37 | if (criteria.getOperator().equals(FilterOperation.gt)) {
38 | return builder.greaterThan(root.get(criteria.getKey()), criteria.getValue().toString());
39 | } else if (criteria.getOperator().equals(FilterOperation.gte)) {
40 | return builder.greaterThanOrEqualTo(root.get(criteria.getKey()), criteria.getValue().toString());
41 | } else if (criteria.getOperator().equals(FilterOperation.lt)) {
42 | return builder.lessThan(root.get(criteria.getKey()), criteria.getValue().toString());
43 | } else if (criteria.getOperator().equals(FilterOperation.lte)) {
44 | return builder.lessThanOrEqualTo(root.get(criteria.getKey()), criteria.getValue().toString());
45 | } else if (criteria.getOperator().equals(FilterOperation.eq)) {
46 | if (root.get(criteria.getKey()).getJavaType() == String.class) {
47 | return builder.like(root.get(criteria.getKey()), "%" + criteria.getValue() + "%");
48 | } else {
49 | return builder.equal(root.get(criteria.getKey()), criteria.getValue());
50 | }
51 | } else if (criteria.getOperator().equals(FilterOperation.ne)) {
52 | return builder.notEqual(root.get(criteria.getKey()), criteria.getValue());
53 | }
54 | }
55 | return null;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/java/com/raydar/filter/EmployeeSpecificationBuilder.java:
--------------------------------------------------------------------------------
1 | package com.raydar.filter;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.springframework.data.jpa.domain.Specification;
7 |
8 | import com.raydar.domain.Employee;
9 |
10 | /**
11 | * @author Rameez.shikalgar
12 | * Employee Specification Builder- Responsible to build specification for Employee Entity as per Search Criteria
13 | */
14 | public class EmployeeSpecificationBuilder {
15 | private final List params;
16 |
17 | public EmployeeSpecificationBuilder() {
18 | params = new ArrayList();
19 | }
20 |
21 | public EmployeeSpecificationBuilder with(SearchCriteria criteria) {
22 | params.add(criteria);
23 | return this;
24 | }
25 |
26 | public Specification build() {
27 | if (params.size() == 0) {
28 | return null;
29 | }
30 |
31 | List> specs = new ArrayList>();
32 | for (SearchCriteria param : params) {
33 | specs.add(new EmployeeSpecification(param));
34 | }
35 |
36 | Specification result = specs.get(0);
37 | for (int i = 1; i < specs.size(); i++) {
38 | result = Specification.where(result).and(specs.get(i));
39 | }
40 | return result;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/java/com/raydar/filter/FilterOperation.java:
--------------------------------------------------------------------------------
1 | package com.raydar.filter;
2 |
3 | /**
4 | * @author Rameez.shikalgar
5 | * Template to hold all supported operations to filter records
6 | */
7 | public enum FilterOperation {
8 |
9 | lt,
10 | lte,
11 | gt,
12 | gte,
13 | eq,
14 | ne;
15 | }
16 |
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/java/com/raydar/filter/SearchCriteria.java:
--------------------------------------------------------------------------------
1 | package com.raydar.filter;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 |
6 | /**
7 | * @author Rameez.shikalgar
8 | *
9 | */
10 | @Data
11 | @AllArgsConstructor
12 | public class SearchCriteria {
13 | private String key;
14 | private FilterOperation operator;
15 | private Object value;
16 | private SortOperation sort;
17 |
18 | @Override
19 | public String toString() {
20 | return "SearchCriteria{" + "key=" + key + ", operator='" + operator + '\'' + ", value='" + value + '\'' + ", sort='"
21 | + sort+ '\'' + '}';
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/java/com/raydar/filter/SortOperation.java:
--------------------------------------------------------------------------------
1 | package com.raydar.filter;
2 |
3 | public enum SortOperation {
4 |
5 | asc,
6 | desc;
7 | }
8 |
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/java/com/raydar/repository/EmployeeJpaRepository.java:
--------------------------------------------------------------------------------
1 | package com.raydar.repository;
2 |
3 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
4 | import org.springframework.data.repository.CrudRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | import com.raydar.domain.Employee;
8 |
9 | @Repository
10 | public interface EmployeeJpaRepository extends CrudRepository, JpaSpecificationExecutor{
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/java/com/raydar/repository/EmployeeJsonRepositoryImpl.java:
--------------------------------------------------------------------------------
1 | package com.raydar.repository;
2 |
3 | import java.io.File;
4 | import java.util.HashSet;
5 | import java.util.Set;
6 |
7 | import org.json.JSONArray;
8 | import org.json.JSONException;
9 | import org.json.JSONObject;
10 | import org.slf4j.Logger;
11 | import org.slf4j.LoggerFactory;
12 | import org.springframework.beans.factory.annotation.Autowired;
13 | import org.springframework.cache.annotation.CacheEvict;
14 | import org.springframework.context.MessageSource;
15 | import org.springframework.context.i18n.LocaleContextHolder;
16 | import org.springframework.stereotype.Repository;
17 |
18 | import com.fasterxml.jackson.core.type.TypeReference;
19 | import com.fasterxml.jackson.databind.ObjectMapper;
20 | import com.raydar.domain.Employee;
21 | import com.raydar.exception.EmployeeNotFoundException;
22 | import com.raydar.util.JsonUtil;
23 | import com.raydar.util.StringUtils;
24 |
25 | /**
26 | * @author Rameez.shikalgar
27 | * JSON Repository- Responsible for JSON CRUD operations
28 | */
29 | @Repository
30 | public class EmployeeJsonRepositoryImpl implements IEmployeeJsonRepository {
31 |
32 | private static Logger logger = LoggerFactory.getLogger(EmployeeJsonRepositoryImpl.class.getName());
33 |
34 | @Autowired
35 | MessageSource messageSource;
36 |
37 | @Autowired
38 | private ObjectMapper mapper;
39 |
40 | @Autowired
41 | private File file;
42 |
43 | @Autowired
44 | private EmployeeJpaRepository jpaRepository;
45 |
46 | @Override
47 | public Set get() throws Exception {
48 |
49 | TypeReference> typeReference = new TypeReference>(){};
50 |
51 | String existingEmployeesStr = JsonUtil.getStringFromFile(file);
52 |
53 | logger.debug("Employee data json:" + existingEmployeesStr);
54 | if(StringUtils.isNullOrEmpty(existingEmployeesStr)){
55 | return null;
56 | }
57 | Set employees = mapper.readValue(existingEmployeesStr,typeReference);
58 | return employees;
59 | }
60 |
61 | @Override
62 | @CacheEvict(value="employeeMap", allEntries=true)
63 | public void save(Employee employee) throws Exception {
64 | Set employees = new HashSet<>();
65 | JSONArray array = new JSONArray();
66 | TypeReference> typeReference = new TypeReference>(){};
67 |
68 | String existingEmployeesStr = JsonUtil.getStringFromFile(file);
69 |
70 | logger.debug("Employee data json:" + existingEmployeesStr);
71 | if(existingEmployeesStr != null && !existingEmployeesStr.isEmpty()){
72 | employees = mapper.readValue(existingEmployeesStr,typeReference);
73 | array = new JSONArray(existingEmployeesStr);
74 | }
75 |
76 | if(employees.add(employee)){
77 | JSONObject object = new JSONObject(mapper.writeValueAsString(employee));
78 | array.put(object);
79 |
80 | JsonUtil.writeJsonFile(file, array.toString());
81 |
82 | jpaRepository.save(employee);
83 | } else {
84 | String errorMessage = messageSource.getMessage("error.employee.duplicate",
85 | new String[] { employee.getId().toString() }, LocaleContextHolder.getLocale());
86 | throw new Exception(errorMessage);
87 | }
88 | }
89 |
90 | @Override
91 | @CacheEvict(value="employeeMap", allEntries=true)
92 | public void update(Employee employee) throws Exception {
93 | JSONArray array = new JSONArray();
94 |
95 | String existingEmployeesStr = JsonUtil.getStringFromFile(file);
96 | if(existingEmployeesStr != null && !existingEmployeesStr.isEmpty()){
97 | array = new JSONArray(existingEmployeesStr);
98 | }
99 |
100 | checkAndRemoveExistingEmplyee(employee.getId(), array);
101 |
102 | JSONObject object = new JSONObject(mapper.writeValueAsString(employee));
103 | array.put(object);
104 |
105 | JsonUtil.writeJsonFile(file, array.toString());
106 | jpaRepository.save(employee);
107 | }
108 |
109 | @Override
110 | @CacheEvict(value="employeeMap", allEntries=true)
111 | public void delete(Long id) throws Exception {
112 | JSONArray array = new JSONArray();
113 |
114 | String existingEmployeesStr = JsonUtil.getStringFromFile(file);
115 | if (existingEmployeesStr != null && !existingEmployeesStr.isEmpty()) {
116 | array = new JSONArray(existingEmployeesStr);
117 | }
118 |
119 | checkAndRemoveExistingEmplyee(id, array);
120 |
121 | JsonUtil.writeJsonFile(file, array.toString());
122 | jpaRepository.delete(new Employee(id));
123 | }
124 |
125 | private void checkAndRemoveExistingEmplyee(Long id, JSONArray array) throws JSONException {
126 | boolean isExist = false;
127 | for (int i = 0; i < array.length(); i++) {
128 | JSONObject jsonObject = array.getJSONObject(i);
129 | Object idObject = jsonObject.get(StringUtils.findIdField(Employee.class));
130 | Long employeeId = Long.valueOf(idObject.toString());
131 | if (employeeId.equals(id)) {
132 | array.remove(i);
133 | isExist = true;
134 | break;
135 | }
136 | }
137 | if(!isExist){
138 | String errorMessage = messageSource.getMessage("error.employee.notfound",
139 | new String[] { id.toString() }, LocaleContextHolder.getLocale());
140 | throw new EmployeeNotFoundException(errorMessage);
141 | }
142 | }
143 |
144 | @Override
145 | @CacheEvict(value="employeeMap", allEntries=true)
146 | public void refreshCache() {
147 | // This method just refreshes employee cache if anything added externally.
148 | }
149 | }
150 |
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/java/com/raydar/repository/IEmployeeJsonRepository.java:
--------------------------------------------------------------------------------
1 | package com.raydar.repository;
2 |
3 | import java.util.Set;
4 |
5 | import com.raydar.domain.Employee;
6 |
7 | public interface IEmployeeJsonRepository {
8 |
9 | public Set get() throws Exception;
10 | public void save(Employee employee) throws Exception;
11 | public void update(Employee employee) throws Exception;
12 | public void delete(Long id) throws Exception;
13 | public void refreshCache();
14 | }
15 |
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/java/com/raydar/service/CacheServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.raydar.service;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 | import java.util.Set;
6 |
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.cache.annotation.Cacheable;
9 | import org.springframework.stereotype.Service;
10 |
11 | import com.raydar.domain.Employee;
12 | import com.raydar.dto.EmployeeDTO;
13 | import com.raydar.repository.EmployeeJpaRepository;
14 | import com.raydar.repository.IEmployeeJsonRepository;
15 |
16 | /**
17 | * @author Rameez.shikalgar
18 | * Holds cache on application start up
19 | */
20 | @Service
21 | public class CacheServiceImpl implements ICacheService {
22 |
23 | @Autowired
24 | private IEmployeeJsonRepository employeeRepository;
25 |
26 | @Autowired
27 | private EmployeeJpaRepository employeeJpaRepository;
28 |
29 | @Override
30 | @Cacheable(value = "employeeMap", key = "#root.methodName")
31 | public Map getEmployeeMap() throws Exception {
32 |
33 | Set employeeList = employeeRepository.get();
34 |
35 | Map employeeMap = new HashMap<>();
36 | if (null != employeeList) {
37 | employeeList.forEach(employee -> employeeMap.put(employee.getId(), new EmployeeDTO(employee.getId(), employee.getFullName(),
38 | employee.getAge(), employee.getSalary())));
39 |
40 | employeeJpaRepository.saveAll(employeeList);
41 | return employeeMap;
42 | }
43 | return null;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/java/com/raydar/service/EmployeeServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.raydar.service;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 | import java.util.Map;
6 | import java.util.Set;
7 |
8 | import org.slf4j.Logger;
9 | import org.slf4j.LoggerFactory;
10 | import org.springframework.beans.BeanUtils;
11 | import org.springframework.beans.factory.annotation.Autowired;
12 | import org.springframework.context.MessageSource;
13 | import org.springframework.context.i18n.LocaleContextHolder;
14 | import org.springframework.data.jpa.domain.Specification;
15 | import org.springframework.stereotype.Service;
16 |
17 | import com.raydar.domain.Employee;
18 | import com.raydar.dto.EmployeeDTO;
19 | import com.raydar.dto.EmployeeDataResponseDTO;
20 | import com.raydar.exception.EmployeeNotFoundException;
21 | import com.raydar.filter.EmployeeSpecificationBuilder;
22 | import com.raydar.filter.SearchCriteria;
23 | import com.raydar.repository.EmployeeJpaRepository;
24 | import com.raydar.repository.IEmployeeJsonRepository;
25 | import com.raydar.util.StringUtils;
26 |
27 | /**
28 | * @author Rameez.shikalgar
29 | * Service APIs which connects to multiple data repositories
30 | */
31 | @Service
32 | public class EmployeeServiceImpl implements IEmployeeService{
33 |
34 | private static Logger logger = LoggerFactory.getLogger(EmployeeServiceImpl.class.getName());
35 |
36 | @Autowired
37 | private ICacheService cacheService;
38 |
39 | @Autowired
40 | MessageSource messageSource;
41 |
42 | @Autowired
43 | private IEmployeeJsonRepository employeeRepository;
44 |
45 | @Autowired
46 | private EmployeeJpaRepository jpaRepository;
47 |
48 | /* (non-Javadoc)
49 | * @see com.raydar.service.IEmployeeService#get(com.raydar.filter.SearchCriteria)
50 | * Service API to fetch employees based on SerachCriteria
51 | */
52 | @Override
53 | public EmployeeDataResponseDTO get(SearchCriteria criteria) throws Exception {
54 |
55 | Iterable employees = jpaRepository.findAll(buildEmployeeSpecification(criteria));
56 |
57 | List data = new ArrayList<>();
58 | employees.forEach(employee -> data.add(
59 | new EmployeeDTO(employee.getId(), employee.getFullName(), employee.getAge(), employee.getSalary())));
60 | return new EmployeeDataResponseDTO(true, data);
61 | }
62 |
63 | @Override
64 | public EmployeeDataResponseDTO save(EmployeeDTO employee) throws Exception {
65 | logger.info("Saving " + employee);
66 | employeeRepository.save(new Employee(employee.getId(), employee.getFullName(), employee.getAge(), employee.getSalary()));
67 |
68 | String successMessage = messageSource.getMessage("success.data.saved",
69 | new String[] { null }, LocaleContextHolder.getLocale());
70 | return new EmployeeDataResponseDTO(true, null, successMessage);
71 | }
72 |
73 | @Override
74 | public EmployeeDataResponseDTO update(EmployeeDTO employee) throws Exception {
75 |
76 | Map employeeMap = cacheService.getEmployeeMap();
77 | if(employeeMap == null || employeeMap.isEmpty()){
78 | String errorMessage = messageSource.getMessage("error.employee.notfound",
79 | new String[] { employee.getId().toString() }, LocaleContextHolder.getLocale());
80 | throw new EmployeeNotFoundException(errorMessage);
81 | }
82 | EmployeeDTO dbEmployee = employeeMap.get(employee.getId());
83 |
84 | if(null == dbEmployee){
85 | String errorMessage = messageSource.getMessage("error.employee.notfound",
86 | new String[] { employee.getId().toString() }, LocaleContextHolder.getLocale());
87 | throw new EmployeeNotFoundException(errorMessage);
88 | }
89 |
90 | String[] nullPropertyNames = StringUtils.getNullPropertyNames(employee);
91 | BeanUtils.copyProperties(employee, dbEmployee, nullPropertyNames);
92 |
93 | employeeRepository.update(new Employee(dbEmployee.getId(), dbEmployee.getFullName(), dbEmployee.getAge(), dbEmployee.getSalary()));
94 |
95 | String successMessage = messageSource.getMessage("success.data.updated",
96 | new String[] { null }, LocaleContextHolder.getLocale());
97 | return new EmployeeDataResponseDTO(true, null, successMessage);
98 | }
99 |
100 | @Override
101 | public EmployeeDataResponseDTO delete(Long id) throws Exception {
102 | logger.info("Deleting employee: " +id);
103 | employeeRepository.delete(id);
104 | String successMessage = messageSource.getMessage("success.data.deleted",
105 | new String[] { null }, LocaleContextHolder.getLocale());
106 | return new EmployeeDataResponseDTO(true, null, successMessage);
107 | }
108 |
109 | @Override
110 | public EmployeeDataResponseDTO filterByAge(SearchCriteria criteria) throws Exception {
111 | criteria.setKey("age");
112 |
113 | logger.info("Aplying: " +criteria);
114 | Iterable employees = jpaRepository.findAll(buildEmployeeSpecification(criteria));
115 |
116 | List data = new ArrayList<>();
117 | employees.forEach(employee -> data.add(
118 | new EmployeeDTO(employee.getId(), employee.getFullName(), employee.getAge(), employee.getSalary())));
119 | return new EmployeeDataResponseDTO(true, data);
120 | }
121 |
122 | @Override
123 | public EmployeeDataResponseDTO refreshCache() throws Exception {
124 | logger.info("Refreshing cache");
125 | employeeRepository.refreshCache();
126 | Set employees = employeeRepository.get();
127 | jpaRepository.saveAll(employees);
128 |
129 | String successMessage = messageSource.getMessage("success.data.refreshed",
130 | new String[] { null }, LocaleContextHolder.getLocale());
131 | return new EmployeeDataResponseDTO(true, null, successMessage);
132 | }
133 |
134 | private static Specification buildEmployeeSpecification(SearchCriteria criteria){
135 | EmployeeSpecificationBuilder builder = new EmployeeSpecificationBuilder();
136 | builder.with(criteria);
137 | return builder.build();
138 | }
139 | }
140 |
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/java/com/raydar/service/ICacheService.java:
--------------------------------------------------------------------------------
1 | package com.raydar.service;
2 |
3 | import java.util.Map;
4 |
5 | import com.raydar.dto.EmployeeDTO;
6 |
7 | public interface ICacheService {
8 |
9 | Map getEmployeeMap() throws Exception;
10 | }
11 |
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/java/com/raydar/service/IEmployeeService.java:
--------------------------------------------------------------------------------
1 | package com.raydar.service;
2 |
3 | import com.raydar.dto.EmployeeDTO;
4 | import com.raydar.dto.EmployeeDataResponseDTO;
5 | import com.raydar.filter.SearchCriteria;
6 |
7 | public interface IEmployeeService {
8 |
9 | EmployeeDataResponseDTO get(SearchCriteria criteria) throws Exception;
10 | EmployeeDataResponseDTO save(EmployeeDTO employee) throws Exception;
11 | EmployeeDataResponseDTO update(EmployeeDTO employee) throws Exception;
12 | EmployeeDataResponseDTO delete(Long id) throws Exception;
13 | EmployeeDataResponseDTO filterByAge(SearchCriteria criteria) throws Exception;
14 | EmployeeDataResponseDTO refreshCache() throws Exception;
15 | }
16 |
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/java/com/raydar/util/DTOBuilder.java:
--------------------------------------------------------------------------------
1 | package com.raydar.util;
2 |
3 | import com.raydar.domain.Employee;
4 | import com.raydar.dto.EmployeeDTO;
5 |
6 | public class DTOBuilder {
7 |
8 | public static EmployeeDTO buildEmployeeDataResponse(Employee employee){
9 | return null;
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/java/com/raydar/util/JsonUtil.java:
--------------------------------------------------------------------------------
1 | package com.raydar.util;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.BufferedWriter;
5 | import java.io.File;
6 | import java.io.FileInputStream;
7 | import java.io.FileNotFoundException;
8 | import java.io.FileWriter;
9 | import java.io.IOException;
10 | import java.io.InputStream;
11 | import java.io.InputStreamReader;
12 |
13 | public class JsonUtil {
14 |
15 | public static String getStringFromFile(File file) throws IOException {
16 | FileInputStream fin = new FileInputStream(file);
17 | String ret = convertStreamToString(fin);
18 | //Make sure you close all streams.
19 | fin.close();
20 | return ret;
21 | }
22 |
23 | public static String convertStreamToString(InputStream is) throws IOException {
24 | BufferedReader reader = new BufferedReader(new InputStreamReader(is));
25 | StringBuilder sb = new StringBuilder();
26 | String line = null;
27 | while ((line = reader.readLine()) != null) {
28 | sb.append(line).append("\n");
29 | }
30 | return sb.toString();
31 | }
32 |
33 | public static void writeJsonFile(File file, String json) throws IOException {
34 | if (!file.exists()) {
35 | file.createNewFile();
36 | }
37 | try (BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file))) {
38 | bufferedWriter.write(json);
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/java/com/raydar/util/StringUtils.java:
--------------------------------------------------------------------------------
1 | package com.raydar.util;
2 |
3 | import java.beans.FeatureDescriptor;
4 | import java.lang.annotation.Annotation;
5 | import java.lang.reflect.Field;
6 | import java.util.stream.Stream;
7 |
8 | import javax.persistence.Id;
9 |
10 | import org.springframework.beans.BeanWrapper;
11 | import org.springframework.beans.BeanWrapperImpl;
12 |
13 | public class StringUtils {
14 |
15 | public static boolean isNullOrEmpty(String string) {
16 | return string == null || string.trim().length() == 0;
17 | }
18 |
19 | public static boolean isNotNullAndNotEmpty(String string) {
20 | return !isNullOrEmpty(string);
21 | }
22 |
23 | public static boolean isNotNull(String string) {
24 | return null != string;
25 | }
26 |
27 | public static boolean isNumeric(String s) {
28 | return s != null ? s.matches("[-+]?\\d*\\.?\\d+") : false;
29 | }
30 |
31 | public static String[] getNullPropertyNames(Object source) {
32 | final BeanWrapper wrappedSource = new BeanWrapperImpl(source);
33 | return Stream.of(wrappedSource.getPropertyDescriptors())
34 | .map(FeatureDescriptor::getName)
35 | .filter(propertyName -> wrappedSource.getPropertyValue(propertyName) == null)
36 | .toArray(String[]::new);
37 | }
38 |
39 | public static String findIdField(Class cls) {
40 | for(Field field : cls.getDeclaredFields()){
41 | Class type = field.getType();
42 | String name = field.getName();
43 | Annotation[] annotations = field.getDeclaredAnnotations();
44 | for (int i = 0; i < annotations.length; i++) {
45 | if (annotations[i].annotationType().equals(Id.class)) {
46 | return name;
47 | }
48 | }
49 | }
50 | return null;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/java/com/raydar/validator/EmployeeValidator.java:
--------------------------------------------------------------------------------
1 | package com.raydar.validator;
2 |
3 | import org.springframework.validation.Errors;
4 | import org.springframework.validation.ValidationUtils;
5 | import org.springframework.validation.Validator;
6 |
7 | import com.raydar.dto.EmployeeDTO;
8 |
9 | public class EmployeeValidator implements Validator{
10 |
11 | @Override
12 | public boolean supports(Class> clazz) {
13 | return EmployeeDTO.class.equals(clazz);
14 | }
15 |
16 | @Override
17 | public void validate(Object target, Errors e) {
18 | ValidationUtils.rejectIfEmpty(e, "id", "id.empty");
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/resources/application-dev.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8110
3 | servlet:
4 | contextPath: /cabaran
5 |
6 | spring:
7 | datasource:
8 | url: jdbc:h2:mem:employee_db;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
9 | platform: h2
10 | username: sa
11 | password:
12 | driverClassName: org.h2.Driver
13 | jpa:
14 | database-platform: org.hibernate.dialect.H2Dialect
15 | hibernate:
16 | ddl-auto: update
17 | h2:
18 | console:
19 | enabled: true
20 | path: /console
21 | settings:
22 | trace: false
23 | web-allow-others: false
24 |
25 | app:
26 | filedir: D:/test
27 | filename: employee.json
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | # config context path to "/" by setting an empty string
2 | spring:
3 | application:
4 | name: EmployeeService
5 | profiles:
6 | active: dev
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
7 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
8 |
9 |
10 |
11 |
13 | logs/cabaran.log
14 |
15 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5p %c{1}:%L - %m%n
16 |
17 |
18 | 10
19 | logs/cabaran.log.%i
20 |
21 |
23 | 10MB
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/resources/messages.properties:
--------------------------------------------------------------------------------
1 | success.data.saved = Data saved successfully;
2 | success.data.updated = Data updated successfully;
3 | success.data.deleted = Data deleted successfully;
4 | success.data.refreshed = Data refreshed successfully;
5 |
6 | error.employee.notfound = No employee found with id {0}
7 | error.employee.duplicate = Cannot add employee with same id
--------------------------------------------------------------------------------
/springboot-json-crud/src/main/resources/messages_my.properties:
--------------------------------------------------------------------------------
1 | success.data.saved = Malaysia: Data saved successfully;
2 | success.data.updated = Data updated successfully;
3 | success.data.deleted = Data deleted successfully;
4 | success.data.refreshed = Data refreshed successfully;
5 |
6 | error.employee.notfound = No employee found with id {0}
7 | error.employee.duplicate = Cannot add employee with same id
--------------------------------------------------------------------------------
/springboot-json-crud/src/test/java/com/raydar/EmployeesControllerTest.java:
--------------------------------------------------------------------------------
1 | package com.raydar;
2 |
3 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
4 |
5 | import org.junit.Before;
6 | import org.junit.FixMethodOrder;
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 | import org.junit.runners.MethodSorters;
10 | import org.springframework.beans.factory.annotation.Autowired;
11 | import org.springframework.boot.test.context.SpringBootTest;
12 | import org.springframework.http.MediaType;
13 | import org.springframework.test.context.ContextConfiguration;
14 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
15 | import org.springframework.test.web.servlet.MockMvc;
16 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
17 | import org.springframework.test.web.servlet.setup.MockMvcBuilders;
18 | import org.springframework.web.context.WebApplicationContext;
19 |
20 | @RunWith(SpringJUnit4ClassRunner.class)
21 | @ContextConfiguration(classes = CabaranApplication.class)
22 | @SpringBootTest
23 | @FixMethodOrder(MethodSorters.NAME_ASCENDING)
24 | public class EmployeesControllerTest {
25 |
26 | private MockMvc mockMvc;
27 |
28 | @Autowired
29 | private WebApplicationContext wac;
30 |
31 | @Before
32 | public void setup() {
33 | this.mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
34 | }
35 |
36 | @Test
37 | public void verifyGetAllEmployees() throws Exception {
38 | mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/employee/get").accept(MediaType.APPLICATION_JSON))
39 | .andExpect(jsonPath("$.status").value(true));
40 | }
41 |
42 | @Test
43 | public void verifyGetSpecificEmployees() throws Exception {
44 | mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/employee/get?key=age&operator=lt&value=10&sort=asc").accept(MediaType.APPLICATION_JSON))
45 | .andExpect(jsonPath("$.status").value(true));
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/springboot-json-crud/src/test/java/com/raydar/SpringBootApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.raydar;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class SpringBootApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 |
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/springboot-json-crud/target/classes/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Implementation-Title: springboot-cabaran-test
3 | Implementation-Version: 0.0.1-SNAPSHOT
4 | Built-By: Rameez.shikalgar
5 | Implementation-Vendor-Id: com.raydar
6 | Build-Jdk: 1.8.0_131
7 | Implementation-URL: https://projects.spring.io/spring-boot/#/spring-bo
8 | ot-starter-parent/cabaran
9 | Created-By: Maven Integration for Eclipse
10 |
11 |
--------------------------------------------------------------------------------
/springboot-json-crud/target/classes/META-INF/maven/com.raydar/cabaran/pom.properties:
--------------------------------------------------------------------------------
1 | #Generated by Maven Integration for Eclipse
2 | #Wed Sep 05 01:46:53 IST 2018
3 | version=0.0.1-SNAPSHOT
4 | groupId=com.raydar
5 | m2e.projectName=cabaran
6 | m2e.projectLocation=C\:\\Users\\Rameez.shikalgar\\git\\cabaran-repo\\cabaran
7 | artifactId=cabaran
8 |
--------------------------------------------------------------------------------
/springboot-json-crud/target/classes/META-INF/maven/com.raydar/cabaran/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.raydar
7 | cabaran
8 | 0.0.1-SNAPSHOT
9 | jar
10 |
11 | springboot-cabaran-test
12 | Spring Boot demo project to solve Cabaran
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 2.0.4.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | UTF-8
24 | 1.8
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter-web
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-data-jpa
36 |
37 |
38 |
39 | org.springframework.boot
40 | spring-boot-starter-actuator
41 |
42 |
43 |
44 | org.springframework.boot
45 | spring-boot-starter-test
46 | test
47 |
48 |
49 |
50 | com.h2database
51 | h2
52 | runtime
53 |
54 |
55 |
56 |
57 | org.json
58 | json
59 | 20180813
60 |
61 |
62 |
63 |
64 | org.projectlombok
65 | lombok
66 |
67 |
68 |
69 |
70 | io.springfox
71 | springfox-swagger2
72 | 2.9.2
73 |
74 |
75 |
76 | io.springfox
77 | springfox-swagger-ui
78 | 2.9.1
79 |
80 |
81 |
82 | org.apache.commons
83 | commons-lang3
84 | 3.6
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 | org.springframework.boot
94 | spring-boot-maven-plugin
95 |
96 |
97 |
98 |
--------------------------------------------------------------------------------
/springboot-json-crud/target/classes/application-dev.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8110
3 | servlet:
4 | contextPath: /cabaran
5 |
6 | spring:
7 | datasource:
8 | url: jdbc:h2:mem:employee_db;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
9 | platform: h2
10 | username: sa
11 | password:
12 | driverClassName: org.h2.Driver
13 | jpa:
14 | database-platform: org.hibernate.dialect.H2Dialect
15 | hibernate:
16 | ddl-auto: update
17 | h2:
18 | console:
19 | enabled: true
20 | path: /console
21 | settings:
22 | trace: false
23 | web-allow-others: false
24 |
25 |
26 | app:
27 | filedir: D:/test
28 | filename: employee.json
29 |
--------------------------------------------------------------------------------
/springboot-json-crud/target/classes/application.yml:
--------------------------------------------------------------------------------
1 | # config context path to "/" by setting an empty string
2 | spring:
3 | application:
4 | name: EmployeeService
5 | profiles:
6 | active: dev
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | springboot-multi-service-launcher
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.wst.common.project.facet.core.builder
10 |
11 |
12 |
13 |
14 | org.eclipse.jdt.core.javabuilder
15 |
16 |
17 |
18 |
19 | org.springframework.ide.eclipse.core.springbuilder
20 |
21 |
22 |
23 |
24 | org.springframework.ide.eclipse.boot.validation.springbootbuilder
25 |
26 |
27 |
28 |
29 | org.eclipse.m2e.core.maven2Builder
30 |
31 |
32 |
33 |
34 |
35 | org.springframework.ide.eclipse.core.springnature
36 | org.eclipse.jdt.core.javanature
37 | org.eclipse.m2e.core.maven2Nature
38 | org.eclipse.wst.common.project.facet.core.nature
39 |
40 |
41 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding/=UTF-8
3 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
3 | org.eclipse.jdt.core.compiler.compliance=1.8
4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5 | org.eclipse.jdt.core.compiler.source=1.8
6 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | activeProfiles=
2 | eclipse.preferences.version=1
3 | resolveWorkspaceProjects=true
4 | version=1
5 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/.settings/org.eclipse.wst.common.project.facet.core.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/README:
--------------------------------------------------------------------------------
1 | Prerequisite: Java8, Maven3+
2 |
3 | This is demo project to illustrate how to run multiple microservices in single JVM
4 | Follow below steps to launch the microservices:
5 | 1) cd springboot-multi-service-launcher
6 | 2) mvn clean install (This may take time as it ll resolve all the dependencies.)
7 | 3) To run all microservices (first-service and second-service at once)
8 | ~ cd launcher
9 | ~ mvn exec:java OR mvn springboot:run
10 |
11 | This will launch both the microservice in single java process. You can use swagger doc for services:
12 | http://localhost:8110/first/swagger-ui.html
13 | http://localhost:8111/second/swagger-ui.html
14 |
15 | You can change ports here /launcher/src/main/resources/application.yml
16 |
17 | 4) You can also start individual microservice as different java processes
18 | ~ cd first-service
19 | ~ mvn springboot:run
20 |
21 | You can change ports here /first-service/src/main/resources/application-dev.yml
22 |
23 | ~ cd second-service
24 | ~ mvn springboot:run
25 |
26 | You can change ports here /second-service/src/main/resources/application-dev.yml
27 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/common-service/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/common-service/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | common-service
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.wst.common.project.facet.core.builder
10 |
11 |
12 |
13 |
14 | org.eclipse.jdt.core.javabuilder
15 |
16 |
17 |
18 |
19 | org.springframework.ide.eclipse.core.springbuilder
20 |
21 |
22 |
23 |
24 | org.springframework.ide.eclipse.boot.validation.springbootbuilder
25 |
26 |
27 |
28 |
29 | org.eclipse.m2e.core.maven2Builder
30 |
31 |
32 |
33 |
34 |
35 | org.springframework.ide.eclipse.core.springnature
36 | org.eclipse.jdt.core.javanature
37 | org.eclipse.m2e.core.maven2Nature
38 | org.eclipse.wst.common.project.facet.core.nature
39 |
40 |
41 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/common-service/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//src/main/java=UTF-8
3 | encoding/=UTF-8
4 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/common-service/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
3 | org.eclipse.jdt.core.compiler.compliance=1.8
4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5 | org.eclipse.jdt.core.compiler.source=1.8
6 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/common-service/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | activeProfiles=
2 | eclipse.preferences.version=1
3 | resolveWorkspaceProjects=true
4 | version=1
5 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/common-service/.settings/org.eclipse.wst.common.project.facet.core.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/common-service/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.rmz
8 | springboot-multi-service-launcher
9 | 0.0.1-SNAPSHOT
10 |
11 | common-service
12 | common-service
13 | http://maven.apache.org
14 |
15 | UTF-8
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | org.apache.maven.plugins
24 | maven-compiler-plugin
25 | 2.3.2
26 |
27 | ${java.version}
28 | ${java.version}
29 |
30 |
31 |
32 | org.springframework.boot
33 | spring-boot-maven-plugin
34 |
35 |
36 | org.springframework.boot.experimental
37 | spring-boot-thin-layout
38 | 1.0.3.RELEASE
39 |
40 |
41 |
42 | true
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/common-service/src/main/java/com/rmz/common/BackendRunner.java:
--------------------------------------------------------------------------------
1 | package com.rmz.common;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.context.ConfigurableApplicationContext;
5 |
6 | public abstract class BackendRunner {
7 | private ConfigurableApplicationContext appContext;
8 | private final Class>[] backendClasses;
9 |
10 | private Object monitor = new Object();
11 | private boolean shouldWait;
12 |
13 | protected BackendRunner(final Class>... backendClasses) {
14 | this.backendClasses = backendClasses;
15 | }
16 |
17 | public void run() {
18 | if(appContext != null) {
19 | throw new IllegalStateException("AppContext must be null to run this backend");
20 | }
21 | runBackendInThread();
22 | waitUntilBackendIsStarted();
23 | }
24 |
25 | private void waitUntilBackendIsStarted() {
26 | try {
27 | synchronized (monitor) {
28 | if(shouldWait) {
29 | monitor.wait();
30 | }
31 | }
32 | } catch (InterruptedException e) {
33 | throw new IllegalStateException(e);
34 | }
35 | }
36 |
37 | private void runBackendInThread() {
38 | final Thread runnerThread = new BackendRunnerThread();
39 | shouldWait = true;
40 | runnerThread.setContextClassLoader(backendClasses[0].getClassLoader());
41 | runnerThread.start();
42 | }
43 |
44 | public void stop() {
45 | SpringApplication.exit(appContext);
46 | appContext = null;
47 | }
48 |
49 | private class BackendRunnerThread extends Thread {
50 | @Override
51 | public void run() {
52 | appContext = SpringApplication.run(backendClasses, new String[]{});
53 | synchronized (monitor) {
54 | shouldWait = false;
55 | monitor.notify();
56 | }
57 | }
58 | }
59 | }
60 |
61 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/common-service/src/main/java/com/rmz/common/CommonRestApplication.java:
--------------------------------------------------------------------------------
1 | package com.rmz.common;
2 |
3 | import org.springframework.boot.autoconfigure.SpringBootApplication;
4 |
5 | @SpringBootApplication
6 | public class CommonRestApplication {
7 | public static void main(String...strings) throws Exception {
8 |
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/first-service/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/first-service/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | first-service
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.wst.common.project.facet.core.builder
10 |
11 |
12 |
13 |
14 | org.eclipse.jdt.core.javabuilder
15 |
16 |
17 |
18 |
19 | org.springframework.ide.eclipse.core.springbuilder
20 |
21 |
22 |
23 |
24 | org.springframework.ide.eclipse.boot.validation.springbootbuilder
25 |
26 |
27 |
28 |
29 | org.eclipse.m2e.core.maven2Builder
30 |
31 |
32 |
33 |
34 |
35 | org.springframework.ide.eclipse.core.springnature
36 | org.eclipse.jdt.core.javanature
37 | org.eclipse.m2e.core.maven2Nature
38 | org.eclipse.wst.common.project.facet.core.nature
39 |
40 |
41 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/first-service/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//src/main/java=UTF-8
3 | encoding//src/main/resources=UTF-8
4 | encoding//src/test/java=UTF-8
5 | encoding/=UTF-8
6 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/first-service/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
3 | org.eclipse.jdt.core.compiler.compliance=1.8
4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5 | org.eclipse.jdt.core.compiler.source=1.8
6 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/first-service/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | activeProfiles=
2 | eclipse.preferences.version=1
3 | resolveWorkspaceProjects=true
4 | version=1
5 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/first-service/.settings/org.eclipse.wst.common.project.facet.core.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/first-service/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.rmz
8 | springboot-multi-service-launcher
9 | 0.0.1-SNAPSHOT
10 |
11 | first-service
12 | first-service
13 | http://maven.apache.org
14 |
15 | UTF-8
16 |
17 |
18 |
19 | com.rmz
20 | common-service
21 | ${project.version}
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/first-service/src/main/java/com/rmz/first/FirstApplication.java:
--------------------------------------------------------------------------------
1 | package com.rmz.first;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class FirstApplication {
8 | public static void main(String[] args) {
9 | SpringApplication.run(FirstApplication.class, args);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/first-service/src/main/java/com/rmz/first/backendRunner/CustomizationBean.java:
--------------------------------------------------------------------------------
1 | package com.rmz.first.backendRunner;
2 |
3 | import org.springframework.beans.factory.annotation.Value;
4 | import org.springframework.boot.web.server.WebServerFactoryCustomizer;
5 | import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
6 |
7 | public class CustomizationBean implements WebServerFactoryCustomizer{
8 |
9 | @Value( "${backend.apps.first.contextPath}" )
10 | private String contextPath;
11 |
12 | @Value( "${backend.apps.first.port}" )
13 | private Integer port;
14 |
15 | @Override
16 | public void customize(ConfigurableServletWebServerFactory factory) {
17 | factory.setContextPath(contextPath);
18 | factory.setPort(port);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/first-service/src/main/java/com/rmz/first/backendRunner/FirstServiceBackendRunner.java:
--------------------------------------------------------------------------------
1 | package com.rmz.first.backendRunner;
2 |
3 | import com.rmz.common.BackendRunner;
4 | import com.rmz.first.FirstApplication;
5 |
6 | public class FirstServiceBackendRunner extends BackendRunner{
7 | public FirstServiceBackendRunner() {
8 | super(FirstApplication.class, CustomizationBean.class);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/first-service/src/main/java/com/rmz/first/config/SwaggerConfig.java:
--------------------------------------------------------------------------------
1 | package com.rmz.first.config;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | import springfox.documentation.builders.PathSelectors;
7 | import springfox.documentation.builders.RequestHandlerSelectors;
8 | import springfox.documentation.spi.DocumentationType;
9 | import springfox.documentation.spring.web.plugins.Docket;
10 | import springfox.documentation.swagger2.annotations.EnableSwagger2;
11 |
12 | @Configuration
13 | @EnableSwagger2
14 | public class SwaggerConfig {
15 |
16 | @Bean
17 | public Docket api() {
18 | return new Docket(DocumentationType.SWAGGER_2).select().apis(
19 | RequestHandlerSelectors.any()).paths(PathSelectors.any()).build();
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/first-service/src/main/java/com/rmz/first/controller/FirstController.java:
--------------------------------------------------------------------------------
1 | package com.rmz.first.controller;
2 |
3 | import org.springframework.web.bind.annotation.RequestMapping;
4 | import org.springframework.web.bind.annotation.RequestMethod;
5 | import org.springframework.web.bind.annotation.RestController;
6 |
7 | @RestController
8 | public class FirstController {
9 |
10 | @RequestMapping(value = "/index", method = RequestMethod.GET)
11 | public String index() throws Exception {
12 | return "Hello from first microservice!";
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/first-service/src/main/resources/application-dev.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8110
3 | servlet:
4 | contextPath: /first
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/first-service/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | # config context path to "/" by setting an empty string
2 | spring:
3 | application:
4 | name: FirstService
5 | profiles:
6 | active: dev
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/first-service/src/test/java/com/rmz/first/AppTest.java:
--------------------------------------------------------------------------------
1 | package com.rmz.first;
2 |
3 | import junit.framework.Test;
4 | import junit.framework.TestCase;
5 | import junit.framework.TestSuite;
6 |
7 | /**
8 | * Unit test for simple App.
9 | */
10 | public class AppTest
11 | extends TestCase
12 | {
13 | /**
14 | * Create the test case
15 | *
16 | * @param testName name of the test case
17 | */
18 | public AppTest( String testName )
19 | {
20 | super( testName );
21 | }
22 |
23 | /**
24 | * @return the suite of tests being tested
25 | */
26 | public static Test suite()
27 | {
28 | return new TestSuite( AppTest.class );
29 | }
30 |
31 | /**
32 | * Rigourous Test :-)
33 | */
34 | public void testApp()
35 | {
36 | assertTrue( true );
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/launcher/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/launcher/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | launcher
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.wst.common.project.facet.core.builder
10 |
11 |
12 |
13 |
14 | org.eclipse.jdt.core.javabuilder
15 |
16 |
17 |
18 |
19 | org.springframework.ide.eclipse.core.springbuilder
20 |
21 |
22 |
23 |
24 | org.springframework.ide.eclipse.boot.validation.springbootbuilder
25 |
26 |
27 |
28 |
29 | org.eclipse.m2e.core.maven2Builder
30 |
31 |
32 |
33 |
34 |
35 | org.springframework.ide.eclipse.core.springnature
36 | org.eclipse.jdt.core.javanature
37 | org.eclipse.m2e.core.maven2Nature
38 | org.eclipse.wst.common.project.facet.core.nature
39 |
40 |
41 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/launcher/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//src/main/java=UTF-8
3 | encoding//src/main/resources=UTF-8
4 | encoding//src/test/java=UTF-8
5 | encoding/=UTF-8
6 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/launcher/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
3 | org.eclipse.jdt.core.compiler.compliance=1.8
4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5 | org.eclipse.jdt.core.compiler.source=1.8
6 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/launcher/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | activeProfiles=
2 | eclipse.preferences.version=1
3 | resolveWorkspaceProjects=true
4 | version=1
5 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/launcher/.settings/org.eclipse.wst.common.project.facet.core.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/launcher/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.rmz
8 | springboot-multi-service-launcher
9 | 0.0.1-SNAPSHOT
10 |
11 | launcher
12 | launcher
13 | http://maven.apache.org
14 |
15 | UTF-8
16 |
17 |
18 |
19 | com.rmz
20 | common-service
21 | ${project.version}
22 |
23 |
24 | com.rmz
25 | first-service
26 | ${project.version}
27 |
28 |
29 | com.rmz
30 | second-service
31 | ${project.version}
32 |
33 |
34 |
35 |
36 |
37 | org.codehaus.mojo
38 | exec-maven-plugin
39 | 1.6.0
40 |
41 | com.rmz.launcher.LauncherApplication
42 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/launcher/src/main/java/com/rmz/launcher/LauncherApplication.java:
--------------------------------------------------------------------------------
1 | package com.rmz.launcher;
2 |
3 | public class LauncherApplication {
4 | public static void main(String[] args) {
5 | try {
6 | MicroservicesStarter.startBackends();
7 | } catch (Exception e) {
8 | // TODO Auto-generated catch block
9 | e.printStackTrace();
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/launcher/src/main/java/com/rmz/launcher/MicroservicesStarter.java:
--------------------------------------------------------------------------------
1 | package com.rmz.launcher;
2 |
3 | import java.io.File;
4 | import java.lang.reflect.InvocationTargetException;
5 | import java.net.URL;
6 | import java.net.URLClassLoader;
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | public class MicroservicesStarter {
11 | private static final List activeBackends = new ArrayList<>();
12 |
13 | public MicroservicesStarter() {
14 | }
15 |
16 | public static void startBackends() throws Exception {
17 |
18 | startBackend("first-service", "com.rmz.first.backendRunner.FirstServiceBackendRunner");
19 | startBackend("second-service", "com.rmz.second.backendRunner.SecondServiceBackendRunner");
20 | }
21 |
22 | private static void startBackend(final String backendProjectName, final String backendClassName) throws Exception {
23 | //URL backendRunnerUrl = new File("../YagnaCommonRest/target/classes").toURI().toURL();
24 | URL runnerUrl = new File("../" + backendProjectName + "/target/classes").toURI().toURL();
25 |
26 | URL[] urls = new URL[] { runnerUrl };
27 |
28 | URLClassLoader cl = new URLClassLoader(urls, MicroservicesStarter.class.getClassLoader());
29 | Class> runnerClass = cl.loadClass(backendClassName);
30 |
31 | Object runnerInstance = runnerClass.newInstance();
32 |
33 | final Backend backend = new Backend(runnerClass, runnerInstance);
34 | activeBackends.add(backend);
35 |
36 | runnerClass.getMethod("run").invoke(runnerInstance);
37 | }
38 |
39 | public static void stopAllBackends()
40 | throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
41 | for (Backend b : activeBackends) {
42 | b.runnerClass.getMethod("stop").invoke(b.runnerInstance);
43 | }
44 | }
45 |
46 | private static class Backend {
47 | private Class> runnerClass;
48 | private Object runnerInstance;
49 |
50 | public Backend(final Class> runnerClass, final Object runnerInstance) {
51 | this.runnerClass = runnerClass;
52 | this.runnerInstance = runnerInstance;
53 | }
54 | }
55 | }
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/launcher/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: Launcher
4 |
5 | backend:
6 | apps:
7 | first:
8 | contextPath: /first
9 | port: 8110
10 | second:
11 | contextPath: /second
12 | port: 8111
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/launcher/src/test/java/com/rmz/launcher/AppTest.java:
--------------------------------------------------------------------------------
1 | package com.rmz.launcher;
2 |
3 | import junit.framework.Test;
4 | import junit.framework.TestCase;
5 | import junit.framework.TestSuite;
6 |
7 | /**
8 | * Unit test for simple App.
9 | */
10 | public class AppTest
11 | extends TestCase
12 | {
13 | /**
14 | * Create the test case
15 | *
16 | * @param testName name of the test case
17 | */
18 | public AppTest( String testName )
19 | {
20 | super( testName );
21 | }
22 |
23 | /**
24 | * @return the suite of tests being tested
25 | */
26 | public static Test suite()
27 | {
28 | return new TestSuite( AppTest.class );
29 | }
30 |
31 | /**
32 | * Rigourous Test :-)
33 | */
34 | public void testApp()
35 | {
36 | assertTrue( true );
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.rmz
7 | springboot-multi-service-launcher
8 | 0.0.1-SNAPSHOT
9 | pom
10 |
11 | springboot-multi-service-launcher
12 | Demo project for launching multiple microservices with one jvm
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 2.0.4.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | UTF-8
24 | 1.8
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter-web
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-test
36 | test
37 |
38 |
39 |
40 |
41 | io.springfox
42 | springfox-swagger2
43 | 2.9.2
44 |
45 |
46 |
47 | io.springfox
48 | springfox-swagger-ui
49 | 2.9.1
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | org.springframework.boot
59 | spring-boot-maven-plugin
60 |
61 |
62 |
63 |
64 |
65 |
66 | common-service
67 | first-service
68 | second-service
69 | launcher
70 |
71 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/second-service/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/second-service/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | second-service
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.wst.common.project.facet.core.builder
10 |
11 |
12 |
13 |
14 | org.eclipse.jdt.core.javabuilder
15 |
16 |
17 |
18 |
19 | org.springframework.ide.eclipse.core.springbuilder
20 |
21 |
22 |
23 |
24 | org.springframework.ide.eclipse.boot.validation.springbootbuilder
25 |
26 |
27 |
28 |
29 | org.eclipse.m2e.core.maven2Builder
30 |
31 |
32 |
33 |
34 |
35 | org.springframework.ide.eclipse.core.springnature
36 | org.eclipse.jdt.core.javanature
37 | org.eclipse.m2e.core.maven2Nature
38 | org.eclipse.wst.common.project.facet.core.nature
39 |
40 |
41 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/second-service/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//src/main/java=UTF-8
3 | encoding//src/main/resources=UTF-8
4 | encoding//src/test/java=UTF-8
5 | encoding/=UTF-8
6 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/second-service/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
3 | org.eclipse.jdt.core.compiler.compliance=1.8
4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5 | org.eclipse.jdt.core.compiler.source=1.8
6 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/second-service/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | activeProfiles=
2 | eclipse.preferences.version=1
3 | resolveWorkspaceProjects=true
4 | version=1
5 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/second-service/.settings/org.eclipse.wst.common.project.facet.core.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/second-service/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.rmz
8 | springboot-multi-service-launcher
9 | 0.0.1-SNAPSHOT
10 |
11 | second-service
12 | second-service
13 | http://maven.apache.org
14 |
15 | UTF-8
16 |
17 |
18 |
19 | com.rmz
20 | common-service
21 | ${project.version}
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/second-service/src/main/java/com/rmz/second/SecondApplication.java:
--------------------------------------------------------------------------------
1 | package com.rmz.second;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SecondApplication {
8 | public static void main(String[] args) {
9 | SpringApplication.run(SecondApplication.class, args);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/second-service/src/main/java/com/rmz/second/backendRunner/CustomizationBean.java:
--------------------------------------------------------------------------------
1 | package com.rmz.second.backendRunner;
2 |
3 | import org.springframework.beans.factory.annotation.Value;
4 | import org.springframework.boot.web.server.WebServerFactoryCustomizer;
5 | import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
6 |
7 | public class CustomizationBean implements WebServerFactoryCustomizer{
8 |
9 | @Value( "${backend.apps.second.contextPath}" )
10 | private String contextPath;
11 |
12 | @Value( "${backend.apps.second.port}" )
13 | private Integer port;
14 |
15 | @Override
16 | public void customize(ConfigurableServletWebServerFactory factory) {
17 | factory.setContextPath(contextPath);
18 | factory.setPort(port);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/second-service/src/main/java/com/rmz/second/backendRunner/SecondServiceBackendRunner.java:
--------------------------------------------------------------------------------
1 | package com.rmz.second.backendRunner;
2 |
3 | import com.rmz.common.BackendRunner;
4 | import com.rmz.second.SecondApplication;
5 |
6 | public class SecondServiceBackendRunner extends BackendRunner{
7 | public SecondServiceBackendRunner() {
8 | super(SecondApplication.class, CustomizationBean.class);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/second-service/src/main/java/com/rmz/second/config/SwaggerConfig.java:
--------------------------------------------------------------------------------
1 | package com.rmz.second.config;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | import springfox.documentation.builders.PathSelectors;
7 | import springfox.documentation.builders.RequestHandlerSelectors;
8 | import springfox.documentation.spi.DocumentationType;
9 | import springfox.documentation.spring.web.plugins.Docket;
10 | import springfox.documentation.swagger2.annotations.EnableSwagger2;
11 |
12 | @Configuration
13 | @EnableSwagger2
14 | public class SwaggerConfig {
15 |
16 | @Bean
17 | public Docket api() {
18 | return new Docket(DocumentationType.SWAGGER_2).select().apis(
19 | RequestHandlerSelectors.any()).paths(PathSelectors.any()).build();
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/second-service/src/main/java/com/rmz/second/controller/SecondController.java:
--------------------------------------------------------------------------------
1 | package com.rmz.second.controller;
2 |
3 | import org.springframework.web.bind.annotation.RequestMapping;
4 | import org.springframework.web.bind.annotation.RequestMethod;
5 | import org.springframework.web.bind.annotation.RestController;
6 |
7 | @RestController
8 | public class SecondController {
9 |
10 | @RequestMapping(value = "/index", method = RequestMethod.GET)
11 | public String index() throws Exception {
12 | return "Hello from second microservice!";
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/second-service/src/main/resources/application-dev.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8111
3 | servlet:
4 | contextPath: /second
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/second-service/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | # config context path to "/" by setting an empty string
2 | spring:
3 | application:
4 | name: SecondService
5 | profiles:
6 | active: dev
--------------------------------------------------------------------------------
/springboot-multi-service-launcher/second-service/src/test/java/com/rmz/second/AppTest.java:
--------------------------------------------------------------------------------
1 | package com.rmz.second;
2 |
3 | import junit.framework.Test;
4 | import junit.framework.TestCase;
5 | import junit.framework.TestSuite;
6 |
7 | /**
8 | * Unit test for simple App.
9 | */
10 | public class AppTest
11 | extends TestCase
12 | {
13 | /**
14 | * Create the test case
15 | *
16 | * @param testName name of the test case
17 | */
18 | public AppTest( String testName )
19 | {
20 | super( testName );
21 | }
22 |
23 | /**
24 | * @return the suite of tests being tested
25 | */
26 | public static Test suite()
27 | {
28 | return new TestSuite( AppTest.class );
29 | }
30 |
31 | /**
32 | * Rigourous Test :-)
33 | */
34 | public void testApp()
35 | {
36 | assertTrue( true );
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/springboot-sample-actuator/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/springboot-sample-actuator/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | springboot-sample-actuator
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.wst.common.project.facet.core.builder
10 |
11 |
12 |
13 |
14 | org.eclipse.jdt.core.javabuilder
15 |
16 |
17 |
18 |
19 | org.springframework.ide.eclipse.core.springbuilder
20 |
21 |
22 |
23 |
24 | org.springframework.ide.eclipse.boot.validation.springbootbuilder
25 |
26 |
27 |
28 |
29 | org.eclipse.m2e.core.maven2Builder
30 |
31 |
32 |
33 |
34 |
35 | org.springframework.ide.eclipse.core.springnature
36 | org.eclipse.jdt.core.javanature
37 | org.eclipse.m2e.core.maven2Nature
38 | org.eclipse.wst.common.project.facet.core.nature
39 |
40 |
41 |
--------------------------------------------------------------------------------
/springboot-sample-actuator/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//src/main/java=UTF-8
3 | encoding//src/main/resources=UTF-8
4 | encoding/=UTF-8
5 |
--------------------------------------------------------------------------------
/springboot-sample-actuator/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
3 | org.eclipse.jdt.core.compiler.compliance=1.8
4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5 | org.eclipse.jdt.core.compiler.source=1.8
6 |
--------------------------------------------------------------------------------
/springboot-sample-actuator/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | activeProfiles=
2 | eclipse.preferences.version=1
3 | resolveWorkspaceProjects=true
4 | version=1
5 |
--------------------------------------------------------------------------------
/springboot-sample-actuator/.settings/org.eclipse.wst.common.project.facet.core.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/springboot-sample-actuator/.springBeans:
--------------------------------------------------------------------------------
1 |
2 |
3 | 1
4 |
5 |
6 |
7 |
8 |
9 |
10 | java:com.rmz.actuator.ActuatorApplication
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/springboot-sample-actuator/README:
--------------------------------------------------------------------------------
1 | Prerequisite: Java8, Maven3+
2 |
3 | This is demo project to illustrate how to monitor health, memory usage and many other metrics for
4 | Spring Boot Applications
5 |
6 | 1) ~ cd springboot-sample-actuator
7 | 2) mvn clean install
8 | 3) mvn springboot:run
9 | 4) This will launch both the microservice. You can use swagger doc for services:
10 | http://localhost:8110/demo/swagger-ui.html
11 |
12 | Monitoring endpoints:
13 | ----------------------
14 | Once started you will get number of endpoints available for you for monitoring purpose
15 | http://localhost:8110/demo/swagger-ui.html#/operation-handler
16 |
17 |
18 | Here are some of the useful endpoints:
19 | http://localhost:8110/demo/actuator/threaddump
20 | http://localhost:8110/demo/actuator/beans
21 | http://localhost:8110/demo/actuator/env
22 | http://localhost:8110/demo/actuator/httpstrace
23 | http://localhost:8110/demo/actuator/metrics/jvm.memory.max
24 | http://localhost:8110/demo/actuator/metrics/jvm.threads.live
25 |
26 |
27 | By default Spring Boot exports metrics to JMX domain. And you have explicitly enalble the endpoints:
28 | Please refer application-dev.yml:
29 | //////////////////////////////////
30 | management.metrics.export.jmx:
31 | domain: com.rmz.actuator
32 | enabled: true
33 | step: 1m
34 |
35 | management:
36 | endpoints:
37 | web:
38 | exposure:
39 | include: "*"
40 | jmx:
41 | exposure:
42 | include: "*"
43 | ///////////////////////////////////
44 |
45 | You can use JConsole for graphical view of all the metrics by connecting to com.rmz.actuator this domain.
46 |
47 | You can use third party micro meter registries as well instead on JMX for nice graphical views.
48 | https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-metrics.html#production-ready-metrics-export-influx
49 |
--------------------------------------------------------------------------------
/springboot-sample-actuator/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.rmz
7 | springboot-sample-actuator
8 | 0.0.1-SNAPSHOT
9 | jar
10 |
11 | springboot-sample-actuator
12 | Demo project for launching multiple microservices with one jvm
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 2.0.4.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | UTF-8
24 | 1.8
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter-web
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-actuator
36 |
37 |
38 |
39 | org.springframework.boot
40 | spring-boot-starter-actuator
41 |
42 |
43 |
48 |
49 | org.springframework.boot
50 | spring-boot-starter-test
51 | test
52 |
53 |
54 |
55 |
56 | io.springfox
57 | springfox-swagger2
58 | 2.9.2
59 |
60 |
61 |
62 | io.springfox
63 | springfox-swagger-ui
64 | 2.9.1
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 | org.springframework.boot
74 | spring-boot-maven-plugin
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/springboot-sample-actuator/src/main/java/com/rmz/actuator/ActuatorApplication.java:
--------------------------------------------------------------------------------
1 | package com.rmz.actuator;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class ActuatorApplication {
8 | public static void main(String[] args) {
9 | SpringApplication.run(ActuatorApplication.class, args);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/springboot-sample-actuator/src/main/java/com/rmz/actuator/config/SwaggerConfig.java:
--------------------------------------------------------------------------------
1 | package com.rmz.actuator.config;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | import springfox.documentation.builders.PathSelectors;
7 | import springfox.documentation.builders.RequestHandlerSelectors;
8 | import springfox.documentation.spi.DocumentationType;
9 | import springfox.documentation.spring.web.plugins.Docket;
10 | import springfox.documentation.swagger2.annotations.EnableSwagger2;
11 |
12 | @Configuration
13 | @EnableSwagger2
14 | public class SwaggerConfig {
15 |
16 | @Bean
17 | public Docket api() {
18 | return new Docket(DocumentationType.SWAGGER_2).select().apis(
19 | RequestHandlerSelectors.any()).paths(PathSelectors.any()).build();
20 | }
21 |
22 | /*AtlasConfig atlasConfig = new AtlasConfig() {
23 |
24 | @Override
25 | public String get(String arg0) {
26 | return null;
27 | }
28 |
29 | };
30 | MeterRegistry registry = new AtlasMeterRegistry(atlasConfig, Clock.SYSTEM);*/
31 | }
32 |
--------------------------------------------------------------------------------
/springboot-sample-actuator/src/main/java/com/rmz/actuator/controller/ActuatorController.java:
--------------------------------------------------------------------------------
1 | package com.rmz.actuator.controller;
2 |
3 | import org.springframework.web.bind.annotation.RequestMapping;
4 | import org.springframework.web.bind.annotation.RequestMethod;
5 | import org.springframework.web.bind.annotation.RestController;
6 |
7 | @RestController
8 | public class ActuatorController {
9 |
10 | @RequestMapping(value = "/index", method = RequestMethod.GET)
11 | public String index() throws Exception {
12 | return "Hello from actuator microservice!";
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/springboot-sample-actuator/src/main/resources/application-dev.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8110
3 | servlet:
4 | contextPath: /demo
5 |
6 | management.metrics.export.jmx:
7 | domain: com.rmz.actuator
8 | enabled: true
9 | step: 1m
10 |
11 | management:
12 | endpoints:
13 | web:
14 | exposure:
15 | include: "*"
16 | jmx:
17 | exposure:
18 | include: "*"
--------------------------------------------------------------------------------
/springboot-sample-actuator/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | # config context path to "/" by setting an empty string
2 | spring:
3 | application:
4 | name: ActuatorService
5 | profiles:
6 | active: dev
--------------------------------------------------------------------------------
/springboot-sample-actuator/target/classes/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Implementation-Title: springboot-sample-actuator
3 | Implementation-Version: 0.0.1-SNAPSHOT
4 | Built-By: Rameez.shikalgar
5 | Implementation-Vendor-Id: com.rmz
6 | Build-Jdk: 1.8.0_131
7 | Implementation-URL: https://projects.spring.io/spring-boot/#/spring-bo
8 | ot-starter-parent/springboot-sample-actuator
9 | Created-By: Maven Integration for Eclipse
10 |
11 |
--------------------------------------------------------------------------------
/springboot-sample-actuator/target/classes/META-INF/maven/com.rmz/springboot-sample-actuator/pom.properties:
--------------------------------------------------------------------------------
1 | #Generated by Maven Integration for Eclipse
2 | #Wed Aug 29 12:42:08 IST 2018
3 | version=0.0.1-SNAPSHOT
4 | groupId=com.rmz
5 | m2e.projectName=springboot-sample-actuator
6 | m2e.projectLocation=C\:\\Users\\Rameez.shikalgar\\git\\springboot-demo-new\\springboot-sample-actuator
7 | artifactId=springboot-sample-actuator
8 |
--------------------------------------------------------------------------------
/springboot-sample-actuator/target/classes/META-INF/maven/com.rmz/springboot-sample-actuator/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.rmz
7 | springboot-sample-actuator
8 | 0.0.1-SNAPSHOT
9 | jar
10 |
11 | springboot-sample-actuator
12 | Demo project for launching multiple microservices with one jvm
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 2.0.4.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | UTF-8
24 | 1.8
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter-web
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-actuator
36 |
37 |
38 |
39 | org.springframework.boot
40 | spring-boot-starter-actuator
41 |
42 |
43 |
48 |
49 | org.springframework.boot
50 | spring-boot-starter-test
51 | test
52 |
53 |
54 |
55 |
56 | io.springfox
57 | springfox-swagger2
58 | 2.9.2
59 |
60 |
61 |
62 | io.springfox
63 | springfox-swagger-ui
64 | 2.9.1
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 | org.springframework.boot
74 | spring-boot-maven-plugin
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/springboot-sample-actuator/target/classes/application-dev.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8110
3 | servlet:
4 | contextPath: /demo
5 |
6 | management.metrics.export.jmx:
7 | domain: com.rmz.actuator
8 | enabled: true
9 | step: 1m
10 |
11 | management:
12 | endpoints:
13 | web:
14 | exposure:
15 | include: "*"
16 | jmx:
17 | exposure:
18 | include: "*"
--------------------------------------------------------------------------------
/springboot-sample-actuator/target/classes/application.yml:
--------------------------------------------------------------------------------
1 | # config context path to "/" by setting an empty string
2 | spring:
3 | application:
4 | name: ActuatorService
5 | profiles:
6 | active: dev
--------------------------------------------------------------------------------
/springboot-sample-ssl/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/springboot-sample-ssl/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | springboot-sample-ssl
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.wst.common.project.facet.core.builder
10 |
11 |
12 |
13 |
14 | org.eclipse.jdt.core.javabuilder
15 |
16 |
17 |
18 |
19 | org.springframework.ide.eclipse.core.springbuilder
20 |
21 |
22 |
23 |
24 | org.springframework.ide.eclipse.boot.validation.springbootbuilder
25 |
26 |
27 |
28 |
29 | org.eclipse.m2e.core.maven2Builder
30 |
31 |
32 |
33 |
34 |
35 | org.springframework.ide.eclipse.core.springnature
36 | org.eclipse.jdt.core.javanature
37 | org.eclipse.m2e.core.maven2Nature
38 | org.eclipse.wst.common.project.facet.core.nature
39 |
40 |
41 |
--------------------------------------------------------------------------------
/springboot-sample-ssl/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//src/main/java=UTF-8
3 | encoding//src/main/resources=UTF-8
4 | encoding/=UTF-8
5 |
--------------------------------------------------------------------------------
/springboot-sample-ssl/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
3 | org.eclipse.jdt.core.compiler.compliance=1.8
4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5 | org.eclipse.jdt.core.compiler.source=1.8
6 |
--------------------------------------------------------------------------------
/springboot-sample-ssl/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | activeProfiles=
2 | eclipse.preferences.version=1
3 | resolveWorkspaceProjects=true
4 | version=1
5 |
--------------------------------------------------------------------------------
/springboot-sample-ssl/.settings/org.eclipse.wst.common.project.facet.core.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/springboot-sample-ssl/.springBeans:
--------------------------------------------------------------------------------
1 |
2 |
3 | 1
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/springboot-sample-ssl/README:
--------------------------------------------------------------------------------
1 | Prerequisite: Java8, Maven3+
2 |
3 | This is demo project to illustrate how to make your http rest endpoints secured (https)
4 | by applying self signed certificates:
5 |
6 | 1) ~ cd springboot-sample-ssl
7 | 2) mvn clean install
8 | 3) mvn springboot:run
9 | 4) This will launch both the microservice. You can use swagger doc for services:
10 | https://localhost:8110/secured/swagger-ui.html
11 |
12 |
13 |
14 | Certificates information:
15 | --------------------------
16 | - You will find certificate details in application-dev.yml file.
17 | - To create your sample certificate using java genkey tool follow below commands.
18 |
19 | 1) keytool -genkey -alias sample_server -keyalg RSA -keysize 2048 -validity 700 -keypass sample -storepass sample -keystore sample-ssl-server.jks
20 | -- Answer further questions related to certificate owner.
21 | -- After answering all question your ceriticate is generated.
22 | 2) keytool -list -keystore sample-ssl-server.jks
23 | -- This is just to know whether cerificate is generated properly or not.
24 | 3) Copy generated certificate file to springboot-sample-ssl/src/main/resources
25 | 4) Enter details of the certificate in application-dev.yml
26 | 5) You are done. Your endpoints are secured now.
27 |
--------------------------------------------------------------------------------
/springboot-sample-ssl/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.rmz
7 | springboot-sample-ssl
8 | 0.0.1-SNAPSHOT
9 | jar
10 |
11 | springboot-sample-ssl
12 | Demo project for launching multiple microservices with one jvm
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 2.0.4.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | UTF-8
24 | 1.8
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter-web
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-test
36 | test
37 |
38 |
39 |
40 |
41 | io.springfox
42 | springfox-swagger2
43 | 2.9.2
44 |
45 |
46 |
47 | io.springfox
48 | springfox-swagger-ui
49 | 2.9.1
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | org.springframework.boot
59 | spring-boot-maven-plugin
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/springboot-sample-ssl/src/main/java/com/rmz/secured/SecuredApplication.java:
--------------------------------------------------------------------------------
1 | package com.rmz.secured;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SecuredApplication {
8 | public static void main(String[] args) {
9 | SpringApplication.run(SecuredApplication.class, args);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/springboot-sample-ssl/src/main/java/com/rmz/secured/config/SwaggerConfig.java:
--------------------------------------------------------------------------------
1 | package com.rmz.secured.config;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | import springfox.documentation.builders.PathSelectors;
7 | import springfox.documentation.builders.RequestHandlerSelectors;
8 | import springfox.documentation.spi.DocumentationType;
9 | import springfox.documentation.spring.web.plugins.Docket;
10 | import springfox.documentation.swagger2.annotations.EnableSwagger2;
11 |
12 | @Configuration
13 | @EnableSwagger2
14 | public class SwaggerConfig {
15 |
16 | @Bean
17 | public Docket api() {
18 | return new Docket(DocumentationType.SWAGGER_2).select().apis(
19 | RequestHandlerSelectors.any()).paths(PathSelectors.any()).build();
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/springboot-sample-ssl/src/main/java/com/rmz/secured/controller/SecuredController.java:
--------------------------------------------------------------------------------
1 | package com.rmz.secured.controller;
2 |
3 | import org.springframework.web.bind.annotation.RequestMapping;
4 | import org.springframework.web.bind.annotation.RequestMethod;
5 | import org.springframework.web.bind.annotation.RestController;
6 |
7 | @RestController
8 | public class SecuredController {
9 |
10 | @RequestMapping(value = "/index", method = RequestMethod.GET)
11 | public String index() throws Exception {
12 | return "Hello from secured microservice!";
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/springboot-sample-ssl/src/main/resources/application-dev.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8110
3 | servlet:
4 | contextPath: /secured
5 | ssl:
6 | key-alias: sample_server
7 | key-password: sample
8 | key-store: classpath:sample-ssl-server.jks
9 | key-store-type: JKS
10 | key-store-provider: SUN
11 | protocol: TLS
12 | enabled: true
--------------------------------------------------------------------------------
/springboot-sample-ssl/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | # config context path to "/" by setting an empty string
2 | spring:
3 | application:
4 | name: FirstService
5 | profiles:
6 | active: dev
--------------------------------------------------------------------------------
/springboot-sample-ssl/src/main/resources/sample-ssl-server.jks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rameez4ever/springboot-demo/960ab1e27d0ffe58650578db8aadd3b9c8f6e2a3/springboot-sample-ssl/src/main/resources/sample-ssl-server.jks
--------------------------------------------------------------------------------