├── README.md ├── angular-spring-boot-mongodb ├── package.json ├── readme.rst └── src │ └── app │ ├── app-routing.module.ts │ ├── app.component.html │ ├── app.component.spec.ts │ ├── app.component.ts │ ├── app.module.ts │ ├── user-add │ ├── user-add.component.html │ ├── user-add.component.spec.ts │ └── user-add.component.ts │ ├── user-detail │ ├── user-detail.component.html │ ├── user-detail.component.spec.ts │ └── user-detail.component.ts │ ├── user-edit │ ├── user-edit.component.html │ ├── user-edit.component.spec.ts │ └── user-edit.component.ts │ ├── user-list │ ├── user-list.component.html │ ├── user-list.component.spec.ts │ └── user-list.component.ts │ ├── user.service.ts │ └── user.ts ├── spring-boot-additional-config ├── additional-properties.properties ├── pom.xml ├── readme.rst └── src │ └── main │ ├── java │ └── com │ │ └── roytuts │ │ └── springboot │ │ └── additionalconfig │ │ └── App.java │ └── resources │ └── application.properties ├── spring-boot-application-properties-inheritance ├── pom.xml ├── readme.rst └── src │ └── main │ ├── java │ └── com │ │ └── roytuts │ │ └── spring │ │ └── boot │ │ └── application │ │ └── properties │ │ └── inheritance │ │ └── Application.java │ └── resources │ ├── application-local.properties │ └── application.properties ├── spring-boot-data-jpa-crud ├── build.gradle ├── readme.rst └── src │ └── main │ ├── java │ ├── com │ │ └── roytuts │ │ │ └── spring │ │ │ └── boot │ │ │ └── data │ │ │ └── jpa │ │ │ └── crud │ │ │ ├── SpringBootDataJpaCrudApp.java │ │ │ ├── entity │ │ │ └── Website.java │ │ │ ├── repository │ │ │ └── WebsiteRepository.java │ │ │ ├── rest │ │ │ └── controller │ │ │ │ └── WebsiteRestController.java │ │ │ ├── service │ │ │ └── WebsiteService.java │ │ │ └── vo │ │ │ └── WebsiteVo.java │ └── spring │ │ └── boot │ │ └── data │ │ └── jpa │ │ └── crud │ │ └── Library.java │ └── resources │ └── application.yml ├── spring-boot-elk-integration ├── elk-spring-2.log ├── elk-spring.log ├── logstash-config.conf ├── pom.xml ├── readme.rst └── src │ └── main │ ├── java │ └── com │ │ └── roytuts │ │ └── spring │ │ └── boot │ │ └── elk │ │ └── SpringELKApp.java │ └── resources │ └── application.properties ├── spring-boot-file-upload ├── build.gradle ├── readme.rst └── src │ └── main │ ├── java │ └── com │ │ └── roytuts │ │ ├── app │ │ └── Application.java │ │ └── rest │ │ └── controller │ │ └── FileController.java │ └── resources │ └── application.properties ├── spring-boot-functional-reactive-microservices ├── readme.rst ├── spring-boot-reactive-currency-conversion-microservice │ ├── build.gradle │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── roytuts │ │ │ └── spring │ │ │ └── boot │ │ │ └── reactive │ │ │ └── currency │ │ │ └── conversion │ │ │ └── microservice │ │ │ ├── app │ │ │ └── ReactiveCurrencyConversionMicroSvcApp.java │ │ │ ├── handler │ │ │ └── CurrencyConversionHandler.java │ │ │ ├── proxy │ │ │ └── CurrencyConversionProxy.java │ │ │ ├── router │ │ │ └── CurrencyConversionRouter.java │ │ │ └── vo │ │ │ └── CurrencyExchange.java │ │ └── resources │ │ └── application.properties ├── spring-boot-reactive-forex-microservice │ ├── build.gradle │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── roytuts │ │ │ └── spring │ │ │ └── boot │ │ │ └── reactive │ │ │ └── forex │ │ │ └── microservice │ │ │ ├── app │ │ │ └── ReactiveForexMicroSvcApp.java │ │ │ ├── entity │ │ │ └── Forex.java │ │ │ ├── handler │ │ │ └── ForexHandler.java │ │ │ ├── repository │ │ │ └── ForexRepository.java │ │ │ ├── router │ │ │ └── ForexRouter.java │ │ │ └── vo │ │ │ └── ForexVo.java │ │ └── resources │ │ └── application.properties └── spring-boot-reactive-microservice-eureka-server-config │ ├── build.gradle │ └── src │ └── main │ ├── java │ └── com │ │ └── roytuts │ │ └── spring │ │ └── boot │ │ └── reactive │ │ └── microservice │ │ └── eureka │ │ └── server │ │ └── config │ │ └── app │ │ └── ReactiveEurekaConfigMicroSvcApp.java │ └── resources │ └── application.properties ├── spring-boot-jquery-multi-step-form ├── pom.xml ├── readme.rst └── src │ └── main │ ├── java │ └── com │ │ └── roytuts │ │ └── spring │ │ └── boot │ │ └── jquery │ │ └── multistep │ │ └── form │ │ ├── App.java │ │ ├── AppController.java │ │ ├── User.java │ │ ├── UserRepository.java │ │ └── UserService.java │ └── resources │ ├── application.properties │ └── templates │ └── index.html ├── spring-boot-logback-siftingappender ├── build.gradle ├── logs │ ├── MDC.log │ ├── Module1.log │ ├── Module2.log │ └── main.log ├── pom.xml ├── readme.rst └── src │ └── main │ ├── java │ └── com │ │ └── roytuts │ │ └── spring │ │ └── boot │ │ └── logback │ │ └── siftingappender │ │ ├── SpringBootLogbackSiftingAppenderApp.java │ │ └── config │ │ └── StartupTrigger.java │ └── resources │ └── logback.xml ├── spring-boot-logback ├── SpringBoot.log ├── build.gradle ├── readme.rst └── src │ └── main │ ├── java │ └── com │ │ └── roytuts │ │ └── spring │ │ └── boot │ │ └── logback │ │ └── SpringBootLogbackApp.java │ └── resources │ └── logback.xml ├── spring-boot-mongodb-crud ├── build.gradle ├── pom.xml ├── readme.rst └── src │ └── main │ ├── java │ └── com │ │ └── roytuts │ │ └── spring │ │ └── boot │ │ └── mongodb │ │ └── crud │ │ ├── app │ │ └── SpringMongoDbJpaCrudApp.java │ │ ├── entity │ │ └── User.java │ │ ├── repository │ │ └── UserRepository.java │ │ ├── rest │ │ └── controller │ │ │ └── UserRestController.java │ │ ├── service │ │ └── UserService.java │ │ └── vo │ │ └── UserVo.java │ └── resources │ └── application.properties ├── spring-boot-multi-module-project ├── email-service │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── roytuts │ │ └── email │ │ └── service │ │ ├── EmailService.java │ │ └── app │ │ └── EmailServiceApp.java ├── pom.xml ├── readme.rst ├── user-service │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── roytuts │ │ └── user │ │ └── service │ │ ├── UserService.java │ │ ├── app │ │ └── UserServiceApp.java │ │ └── model │ │ └── User.java └── web-service │ ├── pom.xml │ └── src │ └── main │ └── java │ └── com │ └── roytuts │ └── web │ └── service │ ├── app │ └── WebServiceApp.java │ └── controller │ └── WebRestController.java ├── spring-boot-mvc-jdbctemplate-crud ├── pom.xml ├── readme.rst └── src │ └── main │ ├── java │ └── com │ │ └── roytuts │ │ └── spring │ │ └── boot │ │ └── mvc │ │ └── jdbctemplate │ │ └── crud │ │ ├── SpringBootMvcJdbcTemplateCrudApp.java │ │ ├── controller │ │ └── TeacherController.java │ │ ├── dao │ │ └── TeacherDao.java │ │ ├── model │ │ └── Teacher.java │ │ ├── rowmapper │ │ └── TeacherRowMapper.java │ │ └── service │ │ └── TeacherService.java │ ├── resources │ └── application.properties │ └── webapp │ └── views │ ├── add.jsp │ ├── teacher.jsp │ ├── teachers.jsp │ └── update.jsp ├── spring-boot-profile-based-logging ├── pom.xml ├── readme.rst └── src │ └── main │ ├── java │ └── com │ │ └── roytuts │ │ └── spring │ │ └── boot │ │ └── profile │ │ └── based │ │ └── logging │ │ └── SpringProfileBasedLoggingApp.java │ └── resources │ ├── application.properties │ └── logback-spring.xml ├── spring-boot-reactive-mongodb-crud ├── build.gradle ├── readme.rst └── src │ └── main │ ├── java │ └── com │ │ └── roytuts │ │ └── spring │ │ └── boot │ │ └── reactive │ │ └── mongodb │ │ └── crud │ │ ├── app │ │ └── ReactiveForexApp.java │ │ ├── entity │ │ └── Forex.java │ │ ├── handler │ │ └── ForexHandler.java │ │ ├── repository │ │ └── ForexRepository.java │ │ ├── router │ │ └── ForexRouter.java │ │ └── vo │ │ └── ForexVo.java │ └── resources │ └── application.properties ├── spring-boot-reload-changes-without-server-restart ├── pom.xml ├── readme.rst └── src │ └── main │ └── java │ └── com │ └── roytuts │ └── spring │ └── boot │ └── reload │ └── changes │ └── without │ └── server │ └── restart │ ├── GreetingController.java │ └── SpringBootChangesWithoutRestartServerApp.java ├── spring-boot-security-sso-oauth2 ├── build.gradle ├── pom.xml ├── readme.rst └── src │ └── main │ ├── java │ └── com │ │ └── roytuts │ │ └── sso │ │ └── oauth2 │ │ ├── SsoOAuth2Application.java │ │ ├── config │ │ ├── SsoConfig.java │ │ └── SsoConfig_270.java │ │ ├── controller │ │ ├── HomeController.java │ │ ├── UserController.java │ │ └── UserController_270.java │ │ └── main │ │ └── SsoOAuth2Application.java │ ├── resources │ ├── application.yml │ └── application_270.yml │ └── webapp │ └── view │ ├── index.jsp │ └── index_270.jsp ├── spring-boot-single-jar-war ├── build.gradle ├── lib │ └── src │ │ └── main │ │ └── java │ │ └── spring │ │ └── boot │ │ └── single │ │ └── jar │ │ └── war │ │ ├── App.java │ │ └── AppRestController.java └── readme.rst ├── spring-boot-use-jetty-instead-of-tomcat ├── build.gradle ├── pom.xml ├── pom.xml_3 ├── readme.rst └── src │ └── main │ └── java │ └── com │ └── roytuts │ └── spring │ └── boot │ └── use │ └── jetty │ └── instead │ └── of │ └── tomcat │ └── SpringBootJettyApp.java ├── spring-boot-web-app-form-validation ├── build.gradle ├── readme.rst └── src │ └── main │ ├── java │ └── spring │ │ └── boot │ │ └── web │ │ └── app │ │ └── form │ │ └── validation │ │ ├── SpringBootWebAppFormValidationApp.java │ │ ├── controller │ │ └── WebAppController.java │ │ └── dto │ │ └── User.java │ └── resources │ └── templates │ └── form.html ├── spring-boot-whitelabel-error-page ├── pom.xml ├── readme.rst └── src │ └── main │ ├── java │ └── com │ │ └── roytuts │ │ └── spring │ │ └── boot │ │ └── whitelabel │ │ └── error │ │ └── page │ │ └── SpringBootWhiteLabelErrorPageApp.java │ └── resources │ └── templates │ └── error.html ├── spring-depends-on-example ├── build.gradle ├── readme.rst ├── settings.gradle └── src │ └── main │ └── java │ └── com │ └── roytuts │ └── spring │ └── depends │ └── on │ └── example │ ├── BeanA.java │ ├── BeanB.java │ ├── BeanC.java │ └── SpringDependsOnApp.java ├── spring-file-upload ├── build.gradle ├── pom.xml ├── readme.rst └── src │ └── main │ └── java │ └── com │ └── roytuts │ └── spring │ └── fileupload │ ├── SpringFileUploadApp.java │ └── rest │ └── controller │ └── FileUploadRestController.java ├── spring-frontend-backend-project ├── .gitattributes ├── .gitignore ├── build.gradle ├── gradlew ├── gradlew.bat ├── readme.rst ├── settings.gradle └── src │ └── main │ ├── java │ └── spring │ │ └── frontend │ │ └── backend │ │ └── project │ │ └── App.java │ └── resources │ └── static │ ├── 3rdpartylicenses.txt │ ├── favicon.ico │ ├── index.html │ ├── main.d63368b497569e63.js │ ├── polyfills.05893be24337104a.js │ ├── runtime.b3427db387de8774.js │ └── styles.ef46db3751d8e999.css ├── spring-google-org-chart ├── emp.sql ├── pom.xml ├── readme.rst └── src │ └── main │ ├── java │ └── com │ │ └── roytuts │ │ └── spring │ │ └── google │ │ └── orgchart │ │ ├── App.java │ │ ├── controller │ │ └── EmployeeController.java │ │ ├── converter │ │ └── EmpDtoEntityConverter.java │ │ ├── dto │ │ └── EmpDto.java │ │ ├── entity │ │ └── Employee.java │ │ ├── repository │ │ └── EmployeeRepository.java │ │ └── service │ │ └── EmployeeService.java │ └── resources │ ├── application.properties │ └── templates │ └── index.html ├── spring-google-pie-chart ├── pom.xml ├── readme.rst └── src │ └── main │ ├── java │ └── com │ │ └── roytuts │ │ └── spring │ │ └── google │ │ └── pie │ │ └── chart │ │ ├── GPieChartApp.java │ │ ├── controller │ │ └── PieChartController.java │ │ ├── dao │ │ └── PieChartDao.java │ │ └── service │ │ └── PieChartService.java │ └── resources │ └── templates │ └── index.html ├── spring-internationalization ├── build.gradle ├── readme.rst └── src │ └── main │ ├── java │ └── com │ │ └── roytuts │ │ └── spring │ │ └── internationalization │ │ ├── SpringInternationalizationApp.java │ │ ├── config │ │ └── SpringInternationalizationConfig.java │ │ └── controller │ │ └── SpringInternationalizationController.java │ ├── resources │ ├── application.properties │ └── i18n │ │ ├── messages.properties │ │ ├── messages_bn.properties │ │ ├── messages_fr.properties │ │ ├── messages_hi.properties │ │ └── messages_nl.properties │ └── webapp │ └── views │ └── i18n.jsp ├── spring-jcache-support ├── build.gradle ├── readme.rst └── src │ └── main │ ├── java │ └── com │ │ └── roytuts │ │ └── spring │ │ └── jcache │ │ └── support │ │ ├── SpringJCacheApp.java │ │ ├── config │ │ └── JCacheConfig.java │ │ ├── model │ │ └── Person.java │ │ └── repository │ │ └── PersonRepository.java │ └── resources │ └── ehcache.xml ├── spring-lookup-method-injection ├── pom.xml ├── readme.rst └── src │ └── main │ └── java │ └── com │ └── roytuts │ └── spring │ └── lookup │ └── method │ └── injection │ ├── BeanA.java │ ├── BeanB.java │ └── SpringLookupMethodInjectionApp.java ├── spring-mvc-autocomplete-input ├── build.gradle ├── pom.xml ├── readme.rst └── src │ └── main │ ├── java │ └── com │ │ └── roytuts │ │ └── spring │ │ └── mvc │ │ └── autocomplete │ │ └── input │ │ ├── SpringMvcAutocompleteInputApp.java │ │ ├── controller │ │ └── HomeController.java │ │ ├── dao │ │ └── AutoCompleteDao.java │ │ ├── rest │ │ └── controller │ │ │ └── AutoCompleteRestController.java │ │ └── service │ │ └── AutoCompleteService.java │ ├── resources │ └── application.properties │ └── webapp │ ├── static │ ├── css │ │ └── style.css │ └── images │ │ └── ui-anim_basic_16x16.gif │ └── views │ └── index.jsp ├── spring-pdf-report-generation ├── ProductPdfReport.pdf ├── build.gradle ├── readme.rst ├── settings.gradle └── src │ └── main │ ├── java │ └── com │ │ └── roytuts │ │ └── pdf │ │ └── report │ │ └── generation │ │ ├── SpringPdfReportApp.java │ │ ├── config │ │ └── Config.java │ │ ├── entity │ │ └── Product.java │ │ ├── repository │ │ └── ProductRepository.java │ │ └── rest │ │ └── controller │ │ └── ProductRestController.java │ └── resources │ └── application.properties ├── spring-service-layer-bean-validation ├── pom.xml ├── readme.rst └── src │ └── main │ └── java │ └── com │ └── roytuts │ └── spring │ └── service │ └── layer │ └── bean │ └── validation │ ├── SpringServiceLayerValidationApp.java │ ├── rest │ └── controller │ │ └── GreetingRestController.java │ ├── service │ └── GreetingService.java │ └── vo │ └── User.java ├── spring-servletcontext-servletconfig ├── build.gradle ├── pom.xml ├── readme.rst └── src │ └── main │ └── java │ └── com │ └── roytuts │ └── spring │ └── servletcontext │ └── servletconfig │ ├── SpringServletContextConfigApp.java │ ├── controller │ └── SpringServletContextConfigController.java │ └── rest │ └── controller │ └── SpringServletContextConfigRestController.java ├── spring-sse-push-notifications ├── readme.rst ├── spring-sse-push-notifications-client │ └── SseClient.html └── spring-sse-push-notifications │ ├── build.gradle │ ├── pom.xml │ └── src │ └── main │ └── java │ └── com │ └── roytuts │ └── spring │ └── sse │ └── push │ └── notification │ ├── SpringSsePushNotificationApp.java │ ├── controller │ └── SsePushNotificationRestController.java │ └── service │ └── SsePushNotificationService.java ├── springboot-filter ├── pom.xml ├── readme.rst └── src │ └── main │ └── java │ └── com │ └── roytuts │ └── springboot │ └── filter │ ├── App.java │ ├── AppRestController.java │ ├── CacheControlFilter.java │ ├── CspControlFilter.java │ └── FilterConfig.java ├── springboot-main-springbootservletinitializer-junit ├── pom.xml ├── readme.rst └── src │ ├── main │ └── java │ │ └── com │ │ └── roytuts │ │ └── springboot │ │ └── main │ │ └── springbootservletinitializer │ │ └── junit │ │ └── App.java │ └── test │ └── java │ └── com │ └── roytuts │ └── springboot │ └── main │ └── springbootservletinitializer │ └── junit │ └── AppTest.java └── websocket-on-spring-mongodb-functional-reactive ├── readme.rst ├── spring-boot-reactive-websocket-mogodb-client ├── app.js └── index.html └── spring-boot-reactive-websocket-mogodb ├── build.gradle └── src └── main ├── java └── com │ └── roytuts │ └── spring │ └── boot │ └── reactive │ └── websocket │ └── mogodb │ ├── app │ └── SpringReactiveWebSocketMongoDbApp.java │ ├── config │ └── WebSocketHandlerConfig.java │ ├── entity │ └── UserSubscription.java │ ├── handler │ └── UserSubscriptionWebSocketHandler.java │ └── repository │ └── UserSubscriptionRepository.java └── resources └── application.properties /README.md: -------------------------------------------------------------------------------- 1 | # spring-boot 2 | Spring Boot related programs 3 | -------------------------------------------------------------------------------- /angular-spring-boot-mongodb/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-spring-boot-mongodb", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build", 8 | "test": "ng test", 9 | "lint": "ng lint", 10 | "e2e": "ng e2e" 11 | }, 12 | "private": true, 13 | "dependencies": { 14 | "@angular/animations": "~7.1.0", 15 | "@angular/common": "~7.1.0", 16 | "@angular/compiler": "~7.1.0", 17 | "@angular/core": "~7.1.0", 18 | "@angular/forms": "~7.1.0", 19 | "@angular/platform-browser": "~7.1.0", 20 | "@angular/platform-browser-dynamic": "~7.1.0", 21 | "@angular/router": "~7.1.0", 22 | "core-js": "^2.5.4", 23 | "rxjs": "~6.3.3", 24 | "tslib": "^1.9.0", 25 | "zone.js": "~0.8.26" 26 | }, 27 | "devDependencies": { 28 | "@angular-devkit/build-angular": "~0.11.0", 29 | "@angular/cli": "~7.1.4", 30 | "@angular/compiler-cli": "~7.1.0", 31 | "@angular/language-service": "~7.1.0", 32 | "@types/node": "~8.9.4", 33 | "@types/jasmine": "~2.8.8", 34 | "@types/jasminewd2": "~2.0.3", 35 | "codelyzer": "~4.5.0", 36 | "jasmine-core": "~2.99.1", 37 | "jasmine-spec-reporter": "~4.2.1", 38 | "karma": "~3.1.1", 39 | "karma-chrome-launcher": "~2.2.0", 40 | "karma-coverage-istanbul-reporter": "~2.0.1", 41 | "karma-jasmine": "~1.1.2", 42 | "karma-jasmine-html-reporter": "^0.2.2", 43 | "protractor": "~5.4.0", 44 | "ts-node": "~7.0.0", 45 | "tslint": "~5.11.0", 46 | "typescript": "~3.1.6" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /angular-spring-boot-mongodb/readme.rst: -------------------------------------------------------------------------------- 1 | Please follow the tutorial https://roytuts.com/angular-spring-boot-mongodb-crud-example 2 | -------------------------------------------------------------------------------- /angular-spring-boot-mongodb/src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | 4 | import { UserListComponent } from './user-list/user-list.component'; 5 | import { UserAddComponent } from './user-add/user-add.component'; 6 | import { UserEditComponent } from './user-edit/user-edit.component'; 7 | import { UserDetailComponent } from './user-detail/user-detail.component'; 8 | 9 | const routes: Routes = [ 10 | { path: '', redirectTo: '/user', pathMatch: 'full' }, 11 | { path: 'user', component: UserListComponent }, 12 | { path: 'detail/:id', component: UserDetailComponent }, 13 | { path: 'edit/:id', component: UserEditComponent }, 14 | { path: 'add', component: UserAddComponent } 15 | ]; 16 | 17 | @NgModule({ 18 | imports: [RouterModule.forRoot(routes)], 19 | exports: [RouterModule] 20 | }) 21 | export class AppRoutingModule { } 22 | -------------------------------------------------------------------------------- /angular-spring-boot-mongodb/src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /angular-spring-boot-mongodb/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from '@angular/core/testing'; 2 | import { RouterTestingModule } from '@angular/router/testing'; 3 | import { AppComponent } from './app.component'; 4 | 5 | describe('AppComponent', () => { 6 | beforeEach(async(() => { 7 | TestBed.configureTestingModule({ 8 | imports: [ 9 | RouterTestingModule 10 | ], 11 | declarations: [ 12 | AppComponent 13 | ], 14 | }).compileComponents(); 15 | })); 16 | 17 | it('should create the app', () => { 18 | const fixture = TestBed.createComponent(AppComponent); 19 | const app = fixture.debugElement.componentInstance; 20 | expect(app).toBeTruthy(); 21 | }); 22 | 23 | it(`should have as title 'angular-flask-mongodb'`, () => { 24 | const fixture = TestBed.createComponent(AppComponent); 25 | const app = fixture.debugElement.componentInstance; 26 | expect(app.title).toEqual('angular-flask-mongodb'); 27 | }); 28 | 29 | it('should render title in a h1 tag', () => { 30 | const fixture = TestBed.createComponent(AppComponent); 31 | fixture.detectChanges(); 32 | const compiled = fixture.debugElement.nativeElement; 33 | expect(compiled.querySelector('h1').textContent).toContain('Welcome to angular-flask-mongodb!'); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /angular-spring-boot-mongodb/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-root', 5 | templateUrl: './app.component.html', 6 | styleUrls: ['./app.component.css'] 7 | }) 8 | export class AppComponent { 9 | title = 'Angular Spring Boot MongoDB CRUD Example'; 10 | } 11 | -------------------------------------------------------------------------------- /angular-spring-boot-mongodb/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | 4 | import { FormsModule } from '@angular/forms'; 5 | import { HttpClientModule } from '@angular/common/http'; 6 | import { AppRoutingModule } from './app-routing.module'; 7 | 8 | import { AppComponent } from './app.component'; 9 | import { UserListComponent } from './user-list/user-list.component'; 10 | import { UserAddComponent } from './user-add/user-add.component'; 11 | import { UserEditComponent } from './user-edit/user-edit.component'; 12 | import { UserDetailComponent } from './user-detail/user-detail.component'; 13 | 14 | @NgModule({ 15 | declarations: [ 16 | AppComponent, 17 | UserListComponent, 18 | UserAddComponent, 19 | UserEditComponent, 20 | UserDetailComponent 21 | ], 22 | imports: [ 23 | BrowserModule, 24 | AppRoutingModule, 25 | FormsModule, 26 | HttpClientModule 27 | ], 28 | providers: [], 29 | bootstrap: [AppComponent] 30 | }) 31 | export class AppModule { } 32 | -------------------------------------------------------------------------------- /angular-spring-boot-mongodb/src/app/user-add/user-add.component.html: -------------------------------------------------------------------------------- 1 |
2 |

Add User Detail

3 |
4 |

5 | 8 |

9 |

10 | 13 |

14 |

15 | 18 |

19 |
20 | 21 | 22 | 23 |
-------------------------------------------------------------------------------- /angular-spring-boot-mongodb/src/app/user-add/user-add.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { UserAddComponent } from './user-add.component'; 4 | 5 | describe('UserAddComponent', () => { 6 | let component: UserAddComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ UserAddComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(UserAddComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /angular-spring-boot-mongodb/src/app/user-add/user-add.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, Input } from '@angular/core'; 2 | 3 | import { Location } from '@angular/common'; 4 | 5 | import { User } from '../user'; 6 | import { UserService } from '../user.service'; 7 | 8 | @Component({ 9 | selector: 'app-user-add', 10 | templateUrl: './user-add.component.html', 11 | styleUrls: ['./user-add.component.css'] 12 | }) 13 | export class UserAddComponent implements OnInit { 14 | 15 | @Input() user: User = { name: '', email: '', pwd: '' }; 16 | 17 | constructor(private userService: UserService, private location: Location) { } 18 | 19 | ngOnInit() { 20 | } 21 | 22 | save(): void { 23 | this.userService.addUser(this.user).subscribe(() => this.goBack()); 24 | } 25 | 26 | goBack(): void { 27 | this.location.back(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /angular-spring-boot-mongodb/src/app/user-detail/user-detail.component.html: -------------------------------------------------------------------------------- 1 |
2 |

{{user.name | uppercase}} Details

3 |
4 |

5 | Name: {{user.name}} 6 |

7 |

8 | Email: {{user.email}} 9 |

10 |
11 | 12 |
-------------------------------------------------------------------------------- /angular-spring-boot-mongodb/src/app/user-detail/user-detail.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { UserDetailComponent } from './user-detail.component'; 4 | 5 | describe('UserDetailComponent', () => { 6 | let component: UserDetailComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ UserDetailComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(UserDetailComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /angular-spring-boot-mongodb/src/app/user-detail/user-detail.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | import { Location } from '@angular/common'; 4 | import { ActivatedRoute } from '@angular/router'; 5 | 6 | import { User } from '../user'; 7 | import { UserService } from '../user.service'; 8 | 9 | @Component({ 10 | selector: 'app-user-detail', 11 | templateUrl: './user-detail.component.html', 12 | styleUrls: ['./user-detail.component.css'] 13 | }) 14 | export class UserDetailComponent implements OnInit { 15 | 16 | user: User; 17 | 18 | constructor(private route: ActivatedRoute, private userService: UserService, private location: Location) { } 19 | 20 | ngOnInit() { 21 | this.getUser(); 22 | } 23 | 24 | getUser(): void { 25 | const id = this.route.snapshot.paramMap.get('id'); 26 | this.userService.getUser(id).subscribe(user => this.user = user); 27 | } 28 | 29 | goBack(): void { 30 | this.location.back(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /angular-spring-boot-mongodb/src/app/user-edit/user-edit.component.html: -------------------------------------------------------------------------------- 1 |
2 |

{{user.name | uppercase}} Details

3 |
4 |

5 | Name: 6 |

7 |

8 | Email: 9 |

10 |
11 | 12 | 13 | 14 |
-------------------------------------------------------------------------------- /angular-spring-boot-mongodb/src/app/user-edit/user-edit.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { UserEditComponent } from './user-edit.component'; 4 | 5 | describe('UserEditComponent', () => { 6 | let component: UserEditComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ UserEditComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(UserEditComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /angular-spring-boot-mongodb/src/app/user-edit/user-edit.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, Input } from '@angular/core'; 2 | 3 | import { Location } from '@angular/common'; 4 | import { ActivatedRoute } from '@angular/router'; 5 | 6 | import { User } from '../user'; 7 | import { UserService } from '../user.service'; 8 | 9 | @Component({ 10 | selector: 'app-user-edit', 11 | templateUrl: './user-edit.component.html', 12 | styleUrls: ['./user-edit.component.css'] 13 | }) 14 | export class UserEditComponent implements OnInit { 15 | 16 | @Input() user: User; 17 | 18 | constructor(private route: ActivatedRoute, private userService: UserService, private location: Location) { } 19 | 20 | ngOnInit() { 21 | this.getUser(); 22 | } 23 | 24 | getUser(): void { 25 | const id = this.route.snapshot.paramMap.get('id'); 26 | this.userService.getUser(id).subscribe(user => this.user = user); 27 | } 28 | 29 | save(): void { 30 | this.userService.updateUser(this.user).subscribe(success=> {this.goBack();}); 31 | } 32 | 33 | goBack(): void { 34 | this.location.back(); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /angular-spring-boot-mongodb/src/app/user-list/user-list.component.html: -------------------------------------------------------------------------------- 1 |

Users

2 |
3 | 4 | Add New User 5 | 6 |
7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 24 | 25 |
IDNameEmailActions
{{user.name}}{{user.email}} 18 | Detail 19 | 20 | Edit 21 | 22 | 23 |
-------------------------------------------------------------------------------- /angular-spring-boot-mongodb/src/app/user-list/user-list.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { UserListComponent } from './user-list.component'; 4 | 5 | describe('UserListComponent', () => { 6 | let component: UserListComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ UserListComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(UserListComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /angular-spring-boot-mongodb/src/app/user-list/user-list.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | import { ActivatedRoute } from '@angular/router'; 4 | import { User } from '../user'; 5 | import { UserService } from '../user.service'; 6 | 7 | @Component({ 8 | selector: 'app-user-list', 9 | templateUrl: './user-list.component.html', 10 | styleUrls: ['./user-list.component.css'] 11 | }) 12 | export class UserListComponent implements OnInit { 13 | 14 | users: User[] = []; 15 | 16 | constructor(private route: ActivatedRoute, private userService: UserService) { } 17 | 18 | ngOnInit() { 19 | this.getUsers(); 20 | } 21 | 22 | getUsers(): void { 23 | this.userService.getUsers().subscribe(users => this.users = users); 24 | } 25 | 26 | delete(user: User): void { 27 | this.userService.deleteUser(user).subscribe(success=> {this.getUsers();}); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /angular-spring-boot-mongodb/src/app/user.ts: -------------------------------------------------------------------------------- 1 | export class User { 2 | id?: string; 3 | name: string; 4 | email: string; 5 | pwd: string; 6 | } -------------------------------------------------------------------------------- /spring-boot-additional-config/additional-properties.properties: -------------------------------------------------------------------------------- 1 | hi=Hi 2 | hello=Hello 3 | -------------------------------------------------------------------------------- /spring-boot-additional-config/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | com.roytuts 6 | spring-boot-additional-config 7 | 0.0.1-SNAPSHOT 8 | 9 | UTF-8 10 | 19 11 | 19 12 | 13 | 14 | org.springframework.boot 15 | spring-boot-starter-parent 16 | 3.1.0 17 | 18 | 19 | 20 | org.springframework.boot 21 | spring-boot-starter 22 | 23 | 24 | 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-maven-plugin 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /spring-boot-additional-config/readme.rst: -------------------------------------------------------------------------------- 1 | Please follow the tutorial https://roytuts.com/additional-configurations-in-spring-boot-application/ 2 | -------------------------------------------------------------------------------- /spring-boot-additional-config/src/main/java/com/roytuts/springboot/additionalconfig/App.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.springboot.additionalconfig; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.boot.CommandLineRunner; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | 8 | @SpringBootApplication 9 | public class App implements CommandLineRunner { 10 | 11 | @Value("${server.port}") 12 | private int port; 13 | 14 | @Value("${hi}") 15 | private String hi; 16 | 17 | @Value("${hello}") 18 | private String hello; 19 | 20 | public static void main(String[] args) { 21 | SpringApplication.run(App.class, args); 22 | } 23 | 24 | @Override 25 | public void run(String... args) throws Exception { 26 | System.out.println("server.port => " + port); 27 | System.out.println("hi => " + hi + ", hello => " + hello); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /spring-boot-additional-config/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8080 2 | -------------------------------------------------------------------------------- /spring-boot-application-properties-inheritance/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 4.0.0 7 | 8 | com.roytuts 9 | spring-boot-application-properties-inheritance 10 | 0.0.1-SNAPSHOT 11 | 12 | 13 | UTF-8 14 | 16 15 | 16 16 | 17 | 18 | 19 | org.springframework.boot 20 | spring-boot-starter-parent 21 | 2.6.2 22 | 23 | 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-devtools 33 | 34 | 35 | 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-maven-plugin 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /spring-boot-application-properties-inheritance/readme.rst: -------------------------------------------------------------------------------- 1 | Please follow the tutorial https://roytuts.com/spring-boot-application-properties-inheritance-override/ -------------------------------------------------------------------------------- /spring-boot-application-properties-inheritance/src/main/java/com/roytuts/spring/boot/application/properties/inheritance/Application.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.application.properties.inheritance; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.boot.CommandLineRunner; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | 8 | @SpringBootApplication 9 | public class Application implements CommandLineRunner { 10 | 11 | @Value("${app.key}") 12 | private String appKey; 13 | 14 | @Value("${app.inherit}") 15 | private String appInherit; 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(Application.class, args); 19 | } 20 | 21 | @Override 22 | public void run(String... args) throws Exception { 23 | System.out.println("appKey: " + appKey); 24 | System.out.println("appInherit: " + appInherit); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /spring-boot-application-properties-inheritance/src/main/resources/application-local.properties: -------------------------------------------------------------------------------- 1 | app.key=app local key -------------------------------------------------------------------------------- /spring-boot-application-properties-inheritance/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | app.key=app key 2 | 3 | app.inherit=inherited value -------------------------------------------------------------------------------- /spring-boot-data-jpa-crud/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.1.6.RELEASE' 4 | } 5 | repositories { 6 | mavenLocal() 7 | mavenCentral() 8 | } 9 | dependencies { 10 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 11 | } 12 | } 13 | 14 | apply plugin: 'java' 15 | apply plugin: 'org.springframework.boot' 16 | 17 | sourceCompatibility = 1.8 18 | targetCompatibility = 1.8 19 | 20 | repositories { 21 | mavenLocal() 22 | mavenCentral() 23 | } 24 | 25 | dependencies { 26 | compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}") 27 | compile("org.springframework.boot:spring-boot-starter-data-jpa:${springBootVersion}") 28 | runtime("com.h2database:h2:1.4.196") 29 | } -------------------------------------------------------------------------------- /spring-boot-data-jpa-crud/readme.rst: -------------------------------------------------------------------------------- 1 | Please follow the tutorial https://roytuts.com/spring-boot-data-jpa-crud-example/ 2 | -------------------------------------------------------------------------------- /spring-boot-data-jpa-crud/src/main/java/com/roytuts/spring/boot/data/jpa/crud/SpringBootDataJpaCrudApp.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.data.jpa.crud; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.domain.EntityScan; 6 | import org.springframework.data.jpa.repository.config.EnableJpaRepositories; 7 | 8 | @EntityScan("com.roytuts.spring.boot.data.jpa.crud.entity") 9 | @EnableJpaRepositories("com.roytuts.spring.boot.data.jpa.crud.repository") 10 | @SpringBootApplication(scanBasePackages = "com.roytuts.spring.boot.data.jpa.crud") 11 | public class SpringBootDataJpaCrudApp { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(SpringBootDataJpaCrudApp.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /spring-boot-data-jpa-crud/src/main/java/com/roytuts/spring/boot/data/jpa/crud/entity/Website.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.data.jpa.crud.entity; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.GenerationType; 6 | import javax.persistence.Id; 7 | 8 | @Entity 9 | public class Website { 10 | 11 | @Id 12 | @GeneratedValue(strategy = GenerationType.IDENTITY) 13 | private Integer id; 14 | private String name; 15 | private String url; 16 | 17 | public Website() { 18 | } 19 | 20 | public Website(Integer id, String name, String url) { 21 | this.id = id; 22 | this.name = name; 23 | this.url = url; 24 | } 25 | 26 | public Integer getId() { 27 | return id; 28 | } 29 | 30 | public void setId(Integer id) { 31 | this.id = id; 32 | } 33 | 34 | public String getName() { 35 | return name; 36 | } 37 | 38 | public void setName(String name) { 39 | this.name = name; 40 | } 41 | 42 | public String getUrl() { 43 | return url; 44 | } 45 | 46 | public void setUrl(String url) { 47 | this.url = url; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /spring-boot-data-jpa-crud/src/main/java/com/roytuts/spring/boot/data/jpa/crud/repository/WebsiteRepository.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.data.jpa.crud.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import com.roytuts.spring.boot.data.jpa.crud.entity.Website; 6 | 7 | public interface WebsiteRepository extends JpaRepository { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /spring-boot-data-jpa-crud/src/main/java/com/roytuts/spring/boot/data/jpa/crud/service/WebsiteService.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.data.jpa.crud.service; 2 | 3 | import java.util.List; 4 | import java.util.stream.Collectors; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import com.roytuts.spring.boot.data.jpa.crud.entity.Website; 10 | import com.roytuts.spring.boot.data.jpa.crud.repository.WebsiteRepository; 11 | import com.roytuts.spring.boot.data.jpa.crud.vo.WebsiteVo; 12 | 13 | @Service 14 | public class WebsiteService { 15 | 16 | @Autowired 17 | private WebsiteRepository repository; 18 | 19 | public List getWebsiteList() { 20 | return repository.findAll().stream().map(w -> { 21 | WebsiteVo vo = new WebsiteVo(w.getId(), w.getName(), w.getUrl()); 22 | return vo; 23 | }).collect(Collectors.toList()); 24 | } 25 | 26 | public WebsiteVo getWebsiteById(Integer id) { 27 | return repository.findById(id).map(w -> { 28 | WebsiteVo vo = new WebsiteVo(w.getId(), w.getName(), w.getUrl()); 29 | return vo; 30 | }).orElseGet(null); 31 | } 32 | 33 | public void saveWebsite(WebsiteVo vo) { 34 | Website website = new Website(); 35 | website.setName(vo.getName()); 36 | website.setUrl(vo.getUrl()); 37 | repository.save(website); 38 | } 39 | 40 | public void updateWebsite(WebsiteVo vo) { 41 | Website website = new Website(vo.getId(), vo.getName(), vo.getUrl()); 42 | repository.save(website); 43 | } 44 | 45 | public void deleteWebsite(WebsiteVo vo) { 46 | Website website = new Website(vo.getId(), vo.getName(), vo.getUrl()); 47 | repository.delete(website); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /spring-boot-data-jpa-crud/src/main/java/com/roytuts/spring/boot/data/jpa/crud/vo/WebsiteVo.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.data.jpa.crud.vo; 2 | 3 | public class WebsiteVo { 4 | 5 | private Integer id; 6 | private String name; 7 | private String url; 8 | 9 | public WebsiteVo() { 10 | } 11 | 12 | public WebsiteVo(Integer id, String name, String url) { 13 | this.id = id; 14 | this.name = name; 15 | this.url = url; 16 | } 17 | 18 | public Integer getId() { 19 | return id; 20 | } 21 | 22 | public void setId(Integer id) { 23 | this.id = id; 24 | } 25 | 26 | public String getName() { 27 | return name; 28 | } 29 | 30 | public void setName(String name) { 31 | this.name = name; 32 | } 33 | 34 | public String getUrl() { 35 | return url; 36 | } 37 | 38 | public void setUrl(String url) { 39 | this.url = url; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /spring-boot-data-jpa-crud/src/main/java/spring/boot/data/jpa/crud/Library.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This Java source file was generated by the Gradle 'init' task. 3 | */ 4 | package spring.boot.data.jpa.crud; 5 | 6 | public class Library { 7 | public boolean someLibraryMethod() { 8 | return true; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /spring-boot-data-jpa-crud/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | jpa: 3 | show-sql: true 4 | h2: 5 | console: 6 | enabled: true -------------------------------------------------------------------------------- /spring-boot-elk-integration/logstash-config.conf: -------------------------------------------------------------------------------- 1 | input { 2 | file { 3 | type => "java" 4 | path => "C:/eclipse_2021_03_R/spring-boot-elk-integration/elk-spring.log" 5 | codec => multiline { 6 | pattern => "^%{TIMESTAMP_ISO8601} " 7 | negate => true 8 | what => "previous" 9 | } 10 | } 11 | } 12 | 13 | filter { 14 | #If log line contains tab character followed by 'at' then tag that entry as stacktrace 15 | if [message] =~ "\tat" { 16 | grok { 17 | match => ["message", "^(\tat)"] 18 | add_tag => ["stacktrace"] 19 | } 20 | } 21 | 22 | date { 23 | match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss Z" ] 24 | } 25 | } 26 | 27 | output { 28 | stdout { 29 | codec => rubydebug 30 | } 31 | elasticsearch { 32 | hosts => ["http://localhost:9200"] 33 | } 34 | } -------------------------------------------------------------------------------- /spring-boot-elk-integration/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 4.0.0 7 | 8 | com.roytuts 9 | spring-boot-elk-integration 10 | 0.0.1-SNAPSHOT 11 | 12 | 13 | UTF-8 14 | 12 15 | 12 16 | 17 | 18 | 19 | org.springframework.boot 20 | spring-boot-starter-parent 21 | 2.4.5 22 | 23 | 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-web 28 | 29 | 30 | 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-maven-plugin 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /spring-boot-elk-integration/readme.rst: -------------------------------------------------------------------------------- 1 | You can read tutorial here https://roytuts.com/elk-stack-integration-with-spring-boot-applications/ -------------------------------------------------------------------------------- /spring-boot-elk-integration/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | logging.file.name=elk-spring.log -------------------------------------------------------------------------------- /spring-boot-file-upload/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.1.2.RELEASE' 4 | } 5 | repositories { 6 | mavenLocal() 7 | mavenCentral() 8 | } 9 | dependencies { 10 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 11 | } 12 | } 13 | 14 | apply plugin: 'java-library' 15 | apply plugin: 'org.springframework.boot' 16 | 17 | repositories { 18 | mavenLocal() 19 | mavenCentral() 20 | } 21 | 22 | dependencies { 23 | compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}") { 24 | exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat' 25 | } 26 | 27 | compile("org.springframework.boot:spring-boot-starter-jetty:${springBootVersion}") 28 | } 29 | 30 | -------------------------------------------------------------------------------- /spring-boot-file-upload/readme.rst: -------------------------------------------------------------------------------- 1 | Please follow the tutorial https://roytuts.com/angular-spring-boot-file-upload-example/ 2 | -------------------------------------------------------------------------------- /spring-boot-file-upload/src/main/java/com/roytuts/app/Application.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.app; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication(scanBasePackages = "com.roytuts") 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-boot-file-upload/src/main/java/com/roytuts/rest/controller/FileController.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.rest.controller; 2 | 3 | import java.io.InputStream; 4 | import java.util.logging.Logger; 5 | 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.http.ResponseEntity; 8 | import org.springframework.web.bind.annotation.CrossOrigin; 9 | import org.springframework.web.bind.annotation.PostMapping; 10 | import org.springframework.web.bind.annotation.RequestParam; 11 | import org.springframework.web.bind.annotation.RestController; 12 | import org.springframework.web.multipart.MultipartFile; 13 | 14 | @RestController 15 | @CrossOrigin(origins = "http://localhost:4200") 16 | public class FileController { 17 | 18 | private static final Logger logger = Logger.getLogger(FileController.class.getName()); 19 | 20 | @PostMapping("/upload") 21 | public ResponseEntity uploadData(@RequestParam("file") MultipartFile file) throws Exception { 22 | 23 | if (file == null) { 24 | throw new RuntimeException("You must select the a file for uploading"); 25 | } 26 | 27 | InputStream inputStream = file.getInputStream(); 28 | String originalName = file.getOriginalFilename(); 29 | String name = file.getName(); 30 | String contentType = file.getContentType(); 31 | long size = file.getSize(); 32 | 33 | logger.info("inputStream: " + inputStream); 34 | logger.info("originalName: " + originalName); 35 | logger.info("name: " + name); 36 | logger.info("contentType: " + contentType); 37 | logger.info("size: " + size); 38 | 39 | // Do processing with uploaded file data in Service layer 40 | 41 | return new ResponseEntity(originalName, HttpStatus.OK); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /spring-boot-file-upload/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=9000 -------------------------------------------------------------------------------- /spring-boot-functional-reactive-microservices/readme.rst: -------------------------------------------------------------------------------- 1 | Please follow the tutorial https://roytuts.com/spring-mongodb-functional-reactive-microservices-example/ 2 | -------------------------------------------------------------------------------- /spring-boot-functional-reactive-microservices/spring-boot-reactive-currency-conversion-microservice/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.1.6.RELEASE' 4 | } 5 | repositories { 6 | mavenCentral() 7 | } 8 | dependencies { 9 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 10 | } 11 | } 12 | 13 | plugins { 14 | id "io.spring.dependency-management" version "1.0.8.RELEASE" 15 | } 16 | 17 | apply plugin: 'java' 18 | apply plugin: 'org.springframework.boot' 19 | 20 | sourceCompatibility = 1.8 21 | targetCompatibility = 1.8 22 | 23 | repositories { 24 | mavenCentral() 25 | } 26 | 27 | 28 | dependencies { 29 | implementation("org.springframework.boot:spring-boot-starter-webflux:${springBootVersion}") 30 | implementation("org.springframework.cloud:spring-cloud-starter-openfeign") 31 | implementation("org.springframework.cloud:spring-cloud-starter-netflix-ribbon") 32 | implementation("org.springframework.cloud:spring-cloud-starter-netflix-eureka-client") 33 | } 34 | 35 | dependencyManagement { 36 | imports { 37 | mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Greenwich.RELEASE' 38 | } 39 | } -------------------------------------------------------------------------------- /spring-boot-functional-reactive-microservices/spring-boot-reactive-currency-conversion-microservice/src/main/java/com/roytuts/spring/boot/reactive/currency/conversion/microservice/app/ReactiveCurrencyConversionMicroSvcApp.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.reactive.currency.conversion.microservice.app; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | import org.springframework.cloud.openfeign.EnableFeignClients; 7 | 8 | @EnableDiscoveryClient 9 | @EnableFeignClients("com.roytuts.spring.boot.reactive.currency.conversion.microservice.proxy") 10 | @SpringBootApplication(scanBasePackages = "com.roytuts.spring.boot.reactive.currency.conversion.microservice") 11 | public class ReactiveCurrencyConversionMicroSvcApp { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(ReactiveCurrencyConversionMicroSvcApp.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /spring-boot-functional-reactive-microservices/spring-boot-reactive-currency-conversion-microservice/src/main/java/com/roytuts/spring/boot/reactive/currency/conversion/microservice/proxy/CurrencyConversionProxy.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.reactive.currency.conversion.microservice.proxy; 2 | 3 | import org.springframework.cloud.netflix.ribbon.RibbonClient; 4 | import org.springframework.cloud.openfeign.FeignClient; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.PathVariable; 7 | 8 | import com.roytuts.spring.boot.reactive.currency.conversion.microservice.vo.CurrencyExchange; 9 | 10 | //@FeignClient(name = "forex-microservice", url = "localhost:8080") 11 | @FeignClient(name = "forex-microservice") 12 | @RibbonClient(name = "forex-microservice") 13 | public interface CurrencyConversionProxy { 14 | 15 | @GetMapping("/forex/fromCur/{fromCur}/toCur/{toCur}") 16 | public CurrencyExchange getCurrency(@PathVariable(name = "fromCur") String fromCur, 17 | @PathVariable(name = "toCur") String toCur); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /spring-boot-functional-reactive-microservices/spring-boot-reactive-currency-conversion-microservice/src/main/java/com/roytuts/spring/boot/reactive/currency/conversion/microservice/router/CurrencyConversionRouter.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.reactive.currency.conversion.microservice.router; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.http.MediaType; 6 | import org.springframework.web.reactive.function.server.RequestPredicates; 7 | import org.springframework.web.reactive.function.server.RouterFunction; 8 | import org.springframework.web.reactive.function.server.RouterFunctions; 9 | import org.springframework.web.reactive.function.server.ServerResponse; 10 | 11 | import com.roytuts.spring.boot.reactive.currency.conversion.microservice.handler.CurrencyConversionHandler; 12 | 13 | @Configuration 14 | public class CurrencyConversionRouter { 15 | 16 | @Bean 17 | public RouterFunction route(CurrencyConversionHandler handler) { 18 | return RouterFunctions.route(RequestPredicates.GET("/currency-exchange/from/{from}/to/{to}/quantity/{quantity}") 19 | .and(RequestPredicates.accept(MediaType.APPLICATION_JSON)), handler::getCurrencyExchange); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /spring-boot-functional-reactive-microservices/spring-boot-reactive-currency-conversion-microservice/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=9090 2 | 3 | spring.application.name=currency-conversion-microservice 4 | 5 | spring.jackson.default-property-inclusion=NON_NULL 6 | 7 | #forex-microservice.ribbon.listOfServers=localhost:8080,localhost:8085 8 | 9 | eureka.client.service-url.default-zone=http://localhost:8761/eureka -------------------------------------------------------------------------------- /spring-boot-functional-reactive-microservices/spring-boot-reactive-forex-microservice/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.1.6.RELEASE' 4 | } 5 | repositories { 6 | mavenCentral() 7 | } 8 | dependencies { 9 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 10 | } 11 | } 12 | 13 | plugins { 14 | id "io.spring.dependency-management" version "1.0.8.RELEASE" 15 | } 16 | 17 | apply plugin: 'java' 18 | apply plugin: 'org.springframework.boot' 19 | 20 | sourceCompatibility = 1.8 21 | targetCompatibility = 1.8 22 | 23 | repositories { 24 | mavenCentral() 25 | } 26 | 27 | 28 | dependencies { 29 | implementation("org.springframework.boot:spring-boot-starter-webflux:${springBootVersion}") 30 | implementation("org.springframework.boot:spring-boot-starter-data-mongodb-reactive:${springBootVersion}") 31 | implementation("org.springframework.cloud:spring-cloud-starter-netflix-eureka-client") 32 | } 33 | 34 | dependencyManagement { 35 | imports { 36 | mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Greenwich.RELEASE' 37 | } 38 | } -------------------------------------------------------------------------------- /spring-boot-functional-reactive-microservices/spring-boot-reactive-forex-microservice/src/main/java/com/roytuts/spring/boot/reactive/forex/microservice/app/ReactiveForexMicroSvcApp.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.reactive.forex.microservice.app; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.domain.EntityScan; 6 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 7 | import org.springframework.data.mongodb.repository.config.EnableReactiveMongoRepositories; 8 | 9 | @EnableDiscoveryClient 10 | @EntityScan("com.roytuts.spring.boot.reactive.forex.microservice.entity") 11 | @EnableReactiveMongoRepositories("com.roytuts.spring.boot.reactive.forex.microservice.repository") 12 | @SpringBootApplication(scanBasePackages = "com.roytuts.spring.boot.reactive.forex.microservice") 13 | public class ReactiveForexMicroSvcApp { 14 | 15 | public static void main(String[] args) { 16 | SpringApplication.run(ReactiveForexMicroSvcApp.class, args); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /spring-boot-functional-reactive-microservices/spring-boot-reactive-forex-microservice/src/main/java/com/roytuts/spring/boot/reactive/forex/microservice/entity/Forex.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.reactive.forex.microservice.entity; 2 | 3 | import org.springframework.data.annotation.Id; 4 | import org.springframework.data.mongodb.core.mapping.Document; 5 | 6 | @Document(collection = "forex") 7 | public class Forex { 8 | 9 | @Id 10 | private String id; 11 | private String fromCur; 12 | private String toCur; 13 | private Double rateCur; 14 | 15 | public Forex() { 16 | } 17 | 18 | public Forex(String id, String fromCur, String toCur, Double rateCur) { 19 | this.id = id; 20 | this.fromCur = fromCur; 21 | this.toCur = toCur; 22 | this.rateCur = rateCur; 23 | } 24 | 25 | public String getId() { 26 | return id; 27 | } 28 | 29 | public void setId(String id) { 30 | this.id = id; 31 | } 32 | 33 | public String getFromCur() { 34 | return fromCur; 35 | } 36 | 37 | public void setFromCur(String fromCur) { 38 | this.fromCur = fromCur; 39 | } 40 | 41 | public String getToCur() { 42 | return toCur; 43 | } 44 | 45 | public void setToCur(String toCur) { 46 | this.toCur = toCur; 47 | } 48 | 49 | public Double getRateCur() { 50 | return rateCur; 51 | } 52 | 53 | public void setRateCur(Double rateCur) { 54 | this.rateCur = rateCur; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /spring-boot-functional-reactive-microservices/spring-boot-reactive-forex-microservice/src/main/java/com/roytuts/spring/boot/reactive/forex/microservice/handler/ForexHandler.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.reactive.forex.microservice.handler; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.http.MediaType; 5 | import org.springframework.stereotype.Component; 6 | import org.springframework.web.reactive.function.server.ServerRequest; 7 | import org.springframework.web.reactive.function.server.ServerResponse; 8 | 9 | import com.roytuts.spring.boot.reactive.forex.microservice.entity.Forex; 10 | import com.roytuts.spring.boot.reactive.forex.microservice.repository.ForexRepository; 11 | import com.roytuts.spring.boot.reactive.forex.microservice.vo.ForexVo; 12 | 13 | import reactor.core.publisher.Mono; 14 | 15 | @Component 16 | public class ForexHandler { 17 | 18 | @Autowired 19 | private ForexRepository repository; 20 | 21 | public Mono getForexByFromCurToCur(ServerRequest request) { 22 | String fromCur = request.pathVariable("fromCur"); 23 | String toCur = request.pathVariable("toCur"); 24 | 25 | Mono notFound = ServerResponse.notFound().build(); 26 | 27 | Mono forex = repository.findByFromCurAndToCur(fromCur, toCur); 28 | 29 | Mono forexVo = Mono.from(forex.map(f -> { 30 | return new ForexVo(f.getId(), f.getFromCur(), f.getToCur(), f.getRateCur()); 31 | })); 32 | 33 | return ServerResponse.ok().contentType(MediaType.APPLICATION_JSON).body(forexVo, ForexVo.class) 34 | .switchIfEmpty(notFound); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /spring-boot-functional-reactive-microservices/spring-boot-reactive-forex-microservice/src/main/java/com/roytuts/spring/boot/reactive/forex/microservice/repository/ForexRepository.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.reactive.forex.microservice.repository; 2 | 3 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 4 | 5 | import com.roytuts.spring.boot.reactive.forex.microservice.entity.Forex; 6 | 7 | import reactor.core.publisher.Mono; 8 | 9 | public interface ForexRepository extends ReactiveCrudRepository { 10 | 11 | Mono findByFromCurAndToCur(String fromCur, String toCur); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-boot-functional-reactive-microservices/spring-boot-reactive-forex-microservice/src/main/java/com/roytuts/spring/boot/reactive/forex/microservice/router/ForexRouter.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.reactive.forex.microservice.router; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.http.MediaType; 6 | import org.springframework.web.reactive.function.server.RequestPredicates; 7 | import org.springframework.web.reactive.function.server.RouterFunction; 8 | import org.springframework.web.reactive.function.server.RouterFunctions; 9 | import org.springframework.web.reactive.function.server.ServerResponse; 10 | 11 | import com.roytuts.spring.boot.reactive.forex.microservice.handler.ForexHandler; 12 | 13 | @Configuration 14 | public class ForexRouter { 15 | 16 | @Bean 17 | public RouterFunction route(ForexHandler handler) { 18 | return RouterFunctions.route(RequestPredicates.GET("/forex/fromCur/{fromCur}/toCur/{toCur}") 19 | .and(RequestPredicates.accept(MediaType.APPLICATION_JSON)), handler::getForexByFromCurToCur); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /spring-boot-functional-reactive-microservices/spring-boot-reactive-forex-microservice/src/main/java/com/roytuts/spring/boot/reactive/forex/microservice/vo/ForexVo.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.reactive.forex.microservice.vo; 2 | 3 | public class ForexVo { 4 | 5 | private String id; 6 | private String fromCur; 7 | private String toCur; 8 | private Double rateCur; 9 | 10 | public ForexVo() { 11 | } 12 | 13 | public ForexVo(String id, String fromCur, String toCur, Double rateCur) { 14 | this.id = id; 15 | this.fromCur = fromCur; 16 | this.toCur = toCur; 17 | this.rateCur = rateCur; 18 | } 19 | 20 | public String getId() { 21 | return id; 22 | } 23 | 24 | public void setId(String id) { 25 | this.id = id; 26 | } 27 | 28 | public String getFromCur() { 29 | return fromCur; 30 | } 31 | 32 | public void setFromCur(String fromCur) { 33 | this.fromCur = fromCur; 34 | } 35 | 36 | public String getToCur() { 37 | return toCur; 38 | } 39 | 40 | public void setToCur(String toCur) { 41 | this.toCur = toCur; 42 | } 43 | 44 | public Double getRateCur() { 45 | return rateCur; 46 | } 47 | 48 | public void setRateCur(Double rateCur) { 49 | this.rateCur = rateCur; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /spring-boot-functional-reactive-microservices/spring-boot-reactive-forex-microservice/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.data.mongodb.database=roytuts 2 | spring.application.name=forex-microservice 3 | 4 | spring.jackson.default-property-inclusion=NON_NULL 5 | 6 | eureka.client.service-url.default-zone=http://localhost:8761/eureka -------------------------------------------------------------------------------- /spring-boot-functional-reactive-microservices/spring-boot-reactive-microservice-eureka-server-config/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.1.6.RELEASE' 4 | } 5 | repositories { 6 | mavenCentral() 7 | } 8 | dependencies { 9 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 10 | } 11 | } 12 | 13 | plugins { 14 | id "io.spring.dependency-management" version "1.0.8.RELEASE" 15 | } 16 | 17 | apply plugin: 'java' 18 | apply plugin: 'org.springframework.boot' 19 | 20 | sourceCompatibility = 1.8 21 | targetCompatibility = 1.8 22 | 23 | repositories { 24 | mavenCentral() 25 | } 26 | 27 | 28 | dependencies { 29 | implementation("org.springframework.cloud:spring-cloud-starter-netflix-eureka-server") 30 | } 31 | 32 | dependencyManagement { 33 | imports { 34 | mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Greenwich.RELEASE' 35 | } 36 | } -------------------------------------------------------------------------------- /spring-boot-functional-reactive-microservices/spring-boot-reactive-microservice-eureka-server-config/src/main/java/com/roytuts/spring/boot/reactive/microservice/eureka/server/config/app/ReactiveEurekaConfigMicroSvcApp.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.reactive.microservice.eureka.server.config.app; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | @EnableEurekaServer 8 | @SpringBootApplication 9 | public class ReactiveEurekaConfigMicroSvcApp { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(ReactiveEurekaConfigMicroSvcApp.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /spring-boot-functional-reactive-microservices/spring-boot-reactive-microservice-eureka-server-config/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8761 2 | spring.application.name=eureka-server-config 3 | eureka.client.register-with-eureka=false 4 | eureka.client.fetch-registry=false -------------------------------------------------------------------------------- /spring-boot-jquery-multi-step-form/readme.rst: -------------------------------------------------------------------------------- 1 | Please follow the tutorial https://roytuts.com/spring-boot-thymeleaf-jquery-multisteps-form/ 2 | -------------------------------------------------------------------------------- /spring-boot-jquery-multi-step-form/src/main/java/com/roytuts/spring/boot/jquery/multistep/form/App.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.jquery.multistep.form; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | //@EntityScan(basePackages = "com.roytuts.spring.boot.jquery.multistep.form") 8 | //@EnableJpaRepositories(basePackages = "com.roytuts.spring.boot.jquery.multistep.form") 9 | public class App { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(App.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /spring-boot-jquery-multi-step-form/src/main/java/com/roytuts/spring/boot/jquery/multistep/form/AppController.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.jquery.multistep.form; 2 | 3 | import javax.validation.Valid; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.validation.BindingResult; 8 | import org.springframework.web.bind.annotation.GetMapping; 9 | import org.springframework.web.bind.annotation.PostMapping; 10 | import org.springframework.web.bind.annotation.ResponseBody; 11 | 12 | @Controller 13 | public class AppController { 14 | 15 | @Autowired 16 | private UserService userService; 17 | 18 | @GetMapping("/") 19 | public String showUserForm(User user) { 20 | return "index"; 21 | } 22 | 23 | @PostMapping("/") 24 | public String validateUserForm(@Valid User user, BindingResult bindingResult) { 25 | if (bindingResult.hasErrors()) { 26 | return "index"; 27 | } 28 | 29 | userService.save(user); 30 | 31 | return "redirect:/success"; 32 | } 33 | 34 | @ResponseBody 35 | @GetMapping("/success") 36 | public String success() { 37 | return "User data successfully saved!"; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /spring-boot-jquery-multi-step-form/src/main/java/com/roytuts/spring/boot/jquery/multistep/form/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.jquery.multistep.form; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | public interface UserRepository extends JpaRepository { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /spring-boot-jquery-multi-step-form/src/main/java/com/roytuts/spring/boot/jquery/multistep/form/UserService.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.jquery.multistep.form; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Service; 5 | 6 | @Service 7 | public class UserService { 8 | 9 | @Autowired 10 | private UserRepository userRepository; 11 | 12 | public void save(final User user) { 13 | userRepository.save(user); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-jquery-multi-step-form/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver 2 | spring.datasource.url=jdbc:mysql://localhost:3306/roytuts 3 | spring.datasource.username=root 4 | spring.datasource.password=root 5 | -------------------------------------------------------------------------------- /spring-boot-logback-siftingappender/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.2.2.RELEASE' 4 | } 5 | repositories { 6 | mavenLocal() 7 | mavenCentral() 8 | } 9 | dependencies { 10 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 11 | } 12 | } 13 | 14 | apply plugin: 'java' 15 | apply plugin: 'org.springframework.boot' 16 | 17 | sourceCompatibility = 12 18 | targetCompatibility = 12 19 | 20 | repositories { 21 | mavenLocal() 22 | mavenCentral() 23 | } 24 | 25 | dependencies { 26 | implementation("org.springframework.boot:spring-boot-starter:${springBootVersion}") 27 | } -------------------------------------------------------------------------------- /spring-boot-logback-siftingappender/logs/MDC.log: -------------------------------------------------------------------------------- 1 | 2019.12.28 12:50:16.636 [DEBUG] com.roytuts.spring.boot.logback.siftingappender.SpringBootLogbackSiftingAppenderApp Debug Message 2 | 2019.12.28 12:50:16.643 [WARN] com.roytuts.spring.boot.logback.siftingappender.SpringBootLogbackSiftingAppenderApp Warn Message 3 | 2019.12.28 12:50:16.643 [ERROR] com.roytuts.spring.boot.logback.siftingappender.SpringBootLogbackSiftingAppenderApp Error Message 4 | 2019.12.28 12:50:16.643 [INFO] com.roytuts.spring.boot.logback.siftingappender.SpringBootLogbackSiftingAppenderApp Info Message 5 | -------------------------------------------------------------------------------- /spring-boot-logback-siftingappender/logs/Module1.log: -------------------------------------------------------------------------------- 1 | 2019.12.28 12:50:16.723 [DEBUG] com.roytuts.spring.boot.logback.siftingappender.SpringBootLogbackSiftingAppenderApp Module1 Debug Message 2 | 2019.12.28 12:50:16.732 [WARN] com.roytuts.spring.boot.logback.siftingappender.SpringBootLogbackSiftingAppenderApp Module1 Warn Message 3 | 2019.12.28 12:50:16.732 [ERROR] com.roytuts.spring.boot.logback.siftingappender.SpringBootLogbackSiftingAppenderApp Module1 Error Message 4 | 2019.12.28 12:50:16.732 [INFO] com.roytuts.spring.boot.logback.siftingappender.SpringBootLogbackSiftingAppenderApp Module1 Info Message 5 | -------------------------------------------------------------------------------- /spring-boot-logback-siftingappender/logs/Module2.log: -------------------------------------------------------------------------------- 1 | 2019.12.28 12:50:16.733 [DEBUG] com.roytuts.spring.boot.logback.siftingappender.SpringBootLogbackSiftingAppenderApp Module2 Debug Message 2 | 2019.12.28 12:50:16.763 [WARN] com.roytuts.spring.boot.logback.siftingappender.SpringBootLogbackSiftingAppenderApp Module2 Warn Message 3 | 2019.12.28 12:50:16.763 [ERROR] com.roytuts.spring.boot.logback.siftingappender.SpringBootLogbackSiftingAppenderApp Module2 Error Message 4 | 2019.12.28 12:50:16.764 [INFO] com.roytuts.spring.boot.logback.siftingappender.SpringBootLogbackSiftingAppenderApp Module2 Info Message 5 | -------------------------------------------------------------------------------- /spring-boot-logback-siftingappender/logs/main.log: -------------------------------------------------------------------------------- 1 | 2019.12.28 12:50:15.767 [INFO] com.roytuts.spring.boot.logback.siftingappender.SpringBootLogbackSiftingAppenderApp Starting SpringBootLogbackSiftingAppenderApp on DESKTOP-KDLKCQ0 with PID 2624 (C:\jee_workspace\spring-boot-logback-siftingappender\bin\main started by SoumitraSarkar in C:\jee_workspace\spring-boot-logback-siftingappender) 2 | 2019.12.28 12:50:15.793 [DEBUG] com.roytuts.spring.boot.logback.siftingappender.SpringBootLogbackSiftingAppenderApp Running with Spring Boot v2.2.2.RELEASE, Spring v5.2.2.RELEASE 3 | 2019.12.28 12:50:15.795 [INFO] com.roytuts.spring.boot.logback.siftingappender.SpringBootLogbackSiftingAppenderApp No active profile set, falling back to default profiles: default 4 | 2019.12.28 12:50:16.632 [INFO] com.roytuts.spring.boot.logback.siftingappender.SpringBootLogbackSiftingAppenderApp Started SpringBootLogbackSiftingAppenderApp in 1.421 seconds (JVM running for 2.404) 5 | 2019.12.28 12:50:16.634 [DEBUG] com.roytuts.spring.boot.logback.siftingappender.SpringBootLogbackSiftingAppenderApp Debug Message 6 | 2019.12.28 12:50:16.635 [WARN] com.roytuts.spring.boot.logback.siftingappender.SpringBootLogbackSiftingAppenderApp Warn Message 7 | 2019.12.28 12:50:16.635 [ERROR] com.roytuts.spring.boot.logback.siftingappender.SpringBootLogbackSiftingAppenderApp Error Message 8 | 2019.12.28 12:50:16.635 [INFO] com.roytuts.spring.boot.logback.siftingappender.SpringBootLogbackSiftingAppenderApp Info Message 9 | -------------------------------------------------------------------------------- /spring-boot-logback-siftingappender/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 4.0.0 7 | 8 | com.roytuts 9 | spring-boot-logback-siftingappender 10 | 0.0.1-SNAPSHOT 11 | 12 | 13 | UTF-8 14 | 19 15 | 19 16 | 17 | 18 | 19 | org.springframework.boot 20 | spring-boot-starter-parent 21 | 3.2.2 22 | 23 | 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter 28 | 29 | 30 | 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-maven-plugin 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /spring-boot-logback-siftingappender/readme.rst: -------------------------------------------------------------------------------- 1 | Please follow the tutorial https://roytuts.com/spring-module-wise-log-using-mdc-in-logback/ 2 | -------------------------------------------------------------------------------- /spring-boot-logback-siftingappender/src/main/java/com/roytuts/spring/boot/logback/siftingappender/config/StartupTrigger.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.logback.siftingappender.config; 2 | 3 | import java.io.File; 4 | import java.util.concurrent.atomic.AtomicBoolean; 5 | 6 | import ch.qos.logback.core.rolling.TriggeringPolicyBase; 7 | 8 | public class StartupTrigger extends TriggeringPolicyBase { 9 | 10 | private AtomicBoolean doRolling = new AtomicBoolean(true); 11 | 12 | @Override 13 | public boolean isTriggeringEvent(File activeFile, E event) { 14 | return doRolling.getAndSet(false); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /spring-boot-logback/SpringBoot.log: -------------------------------------------------------------------------------- 1 | 28-12-2019 13:11:37.779 [main] INFO c.r.s.b.l.s.SpringBootLogbackSiftingAppenderApp - 2 | Starting SpringBootLogbackSiftingAppenderApp on DESKTOP-KDLKCQ0 with PID 18328 (C:\jee_workspace\spring-boot-logback-siftingappender\bin\main started by SoumitraSarkar in C:\jee_workspace\spring-boot-logback-siftingappender) 3 | 28-12-2019 13:11:37.783 [main] INFO c.r.s.b.l.s.SpringBootLogbackSiftingAppenderApp - 4 | No active profile set, falling back to default profiles: default 5 | 28-12-2019 13:11:38.579 [main] INFO c.r.s.b.l.s.SpringBootLogbackSiftingAppenderApp - 6 | Started SpringBootLogbackSiftingAppenderApp in 1.407 seconds (JVM running for 2.31) 7 | 28-12-2019 13:11:38.581 [main] WARN c.r.s.b.l.s.SpringBootLogbackSiftingAppenderApp - 8 | Warn Message 9 | 28-12-2019 13:11:38.581 [main] ERROR c.r.s.b.l.s.SpringBootLogbackSiftingAppenderApp - 10 | Error Message 11 | 28-12-2019 13:11:38.581 [main] INFO c.r.s.b.l.s.SpringBootLogbackSiftingAppenderApp - 12 | Info Message 13 | -------------------------------------------------------------------------------- /spring-boot-logback/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.2.2.RELEASE' 4 | } 5 | repositories { 6 | mavenLocal() 7 | mavenCentral() 8 | } 9 | dependencies { 10 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 11 | } 12 | } 13 | 14 | apply plugin: 'java' 15 | apply plugin: 'org.springframework.boot' 16 | 17 | sourceCompatibility = 12 18 | targetCompatibility = 12 19 | 20 | repositories { 21 | mavenLocal() 22 | mavenCentral() 23 | } 24 | 25 | dependencies { 26 | implementation("org.springframework.boot:spring-boot-starter:${springBootVersion}") 27 | } -------------------------------------------------------------------------------- /spring-boot-logback/readme.rst: -------------------------------------------------------------------------------- 1 | Please follow the tutorial https://roytuts.com/logging-configuration-in-spring-boot/ 2 | -------------------------------------------------------------------------------- /spring-boot-logback/src/main/java/com/roytuts/spring/boot/logback/SpringBootLogbackApp.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.logback; 2 | 3 | import org.apache.logging.log4j.ThreadContext; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.slf4j.MDC; 7 | import org.springframework.boot.CommandLineRunner; 8 | import org.springframework.boot.SpringApplication; 9 | import org.springframework.boot.autoconfigure.SpringBootApplication; 10 | 11 | @SpringBootApplication 12 | public class SpringBootLogbackApp implements CommandLineRunner { 13 | 14 | private static final Logger LOG = LoggerFactory.getLogger(SpringBootLogbackApp.class); 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(SpringBootLogbackApp.class, args); 18 | } 19 | 20 | @Override 21 | public void run(String... args) throws Exception { 22 | printLog(); 23 | } 24 | 25 | private static void printLog() { 26 | LOG.debug("Debug Message"); 27 | LOG.warn("Warn Message"); 28 | LOG.error("Error Message"); 29 | LOG.info("Info Message"); 30 | LOG.trace("Trace Message"); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /spring-boot-logback/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | %d{dd-MM-yyyy HH:mm:ss.SSS} [%thread] %-5level %logger{36} - 8 | %msg%n 9 | 10 | 11 | 12 | 13 | 14 | SpringBoot.log 15 | 16 | %d{dd-MM-yyyy HH:mm:ss.SSS} [%thread] %-5level %logger{36} - 17 | %msg%n 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /spring-boot-mongodb-crud/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.1.6.RELEASE' 4 | } 5 | repositories { 6 | mavenLocal() 7 | mavenCentral() 8 | } 9 | dependencies { 10 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 11 | } 12 | } 13 | 14 | apply plugin: 'java' 15 | apply plugin: 'org.springframework.boot' 16 | 17 | sourceCompatibility = 1.8 18 | targetCompatibility = 1.8 19 | 20 | repositories { 21 | mavenLocal() 22 | mavenCentral() 23 | } 24 | 25 | dependencies { 26 | compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}") 27 | compile("org.springframework.boot:spring-boot-starter-data-mongodb:${springBootVersion}") 28 | } -------------------------------------------------------------------------------- /spring-boot-mongodb-crud/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 4.0.0 7 | 8 | com.roytuts 9 | spring-boot-mongodb-crud 10 | 0.0.1-SNAPSHOT 11 | 12 | 13 | UTF-8 14 | 19 15 | 19 16 | 17 | 18 | 19 | org.springframework.boot 20 | spring-boot-starter-parent 21 | 3.1.5 22 | 23 | 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-web 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-data-mongodb 33 | 34 | 35 | 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-maven-plugin 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /spring-boot-mongodb-crud/readme.rst: -------------------------------------------------------------------------------- 1 | Please follow the tutorial https://roytuts.com/spring-boot-mongodb-crud-example/ 2 | -------------------------------------------------------------------------------- /spring-boot-mongodb-crud/src/main/java/com/roytuts/spring/boot/mongodb/crud/app/SpringMongoDbJpaCrudApp.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.mongodb.crud.app; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.domain.EntityScan; 6 | import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; 7 | 8 | @EntityScan("com.roytuts.spring.boot.mongodb.crud.entity") 9 | @EnableMongoRepositories("com.roytuts.spring.boot.mongodb.crud.repository") 10 | @SpringBootApplication(scanBasePackages = "com.roytuts.spring.boot.mongodb.crud") 11 | public class SpringMongoDbJpaCrudApp { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(SpringMongoDbJpaCrudApp.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /spring-boot-mongodb-crud/src/main/java/com/roytuts/spring/boot/mongodb/crud/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.mongodb.crud.entity; 2 | 3 | import org.springframework.data.annotation.Id; 4 | 5 | public class User { 6 | 7 | @Id 8 | private String id; 9 | private String name; 10 | private String email; 11 | private String pwd; 12 | 13 | public String getId() { 14 | return id; 15 | } 16 | 17 | public void setId(String id) { 18 | this.id = id; 19 | } 20 | 21 | public String getName() { 22 | return name; 23 | } 24 | 25 | public void setName(String name) { 26 | this.name = name; 27 | } 28 | 29 | public String getEmail() { 30 | return email; 31 | } 32 | 33 | public void setEmail(String email) { 34 | this.email = email; 35 | } 36 | 37 | public String getPwd() { 38 | return pwd; 39 | } 40 | 41 | public void setPwd(String pwd) { 42 | this.pwd = pwd; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /spring-boot-mongodb-crud/src/main/java/com/roytuts/spring/boot/mongodb/crud/repository/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.mongodb.crud.repository; 2 | 3 | import org.springframework.data.mongodb.repository.MongoRepository; 4 | 5 | import com.roytuts.spring.boot.mongodb.crud.entity.User; 6 | 7 | public interface UserRepository extends MongoRepository { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /spring-boot-mongodb-crud/src/main/java/com/roytuts/spring/boot/mongodb/crud/vo/UserVo.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.mongodb.crud.vo; 2 | 3 | public class UserVo { 4 | 5 | private String id; 6 | private String name; 7 | private String email; 8 | private String pwd; 9 | 10 | public String getId() { 11 | return id; 12 | } 13 | 14 | public void setId(String id) { 15 | this.id = id; 16 | } 17 | 18 | public String getName() { 19 | return name; 20 | } 21 | 22 | public void setName(String name) { 23 | this.name = name; 24 | } 25 | 26 | public String getEmail() { 27 | return email; 28 | } 29 | 30 | public void setEmail(String email) { 31 | this.email = email; 32 | } 33 | 34 | public String getPwd() { 35 | return pwd; 36 | } 37 | 38 | public void setPwd(String pwd) { 39 | this.pwd = pwd; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /spring-boot-mongodb-crud/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.data.mongodb.host=127.0.0.1 2 | spring.data.mongodb.port=27017 3 | spring.data.mongodb.database=roytuts 4 | 5 | spring.jackson.default-property-inclusion=NON_NULL -------------------------------------------------------------------------------- /spring-boot-multi-module-project/email-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 4.0.0 7 | 8 | 9 | com.roytuts 10 | spring-boot-multi-module-project 11 | 0.0.1-SNAPSHOT 12 | 13 | 14 | email-service 15 | 16 | 17 | UTF-8 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /spring-boot-multi-module-project/email-service/src/main/java/com/roytuts/email/service/EmailService.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.email.service; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | @Service 6 | public class EmailService { 7 | 8 | public void sendEmail(final String toAddress) { 9 | // send email to toAddress 10 | System.out.println("Email successfully sent"); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-boot-multi-module-project/email-service/src/main/java/com/roytuts/email/service/app/EmailServiceApp.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.email.service.app; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication(scanBasePackages = "com.roytuts.email.service") 7 | public class EmailServiceApp { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(EmailServiceApp.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-boot-multi-module-project/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.roytuts 8 | spring-boot-multi-module-project 9 | 0.0.1-SNAPSHOT 10 | pom 11 | 12 | 13 | org.springframework.boot 14 | spring-boot-starter-parent 15 | 2.1.8.RELEASE 16 | 17 | 18 | 19 | UTF-8 20 | 12 21 | 22 | 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-web 27 | 28 | 29 | 30 | 31 | email-service 32 | user-service 33 | web-service 34 | 35 | 36 | 37 | 38 | 39 | org.apache.maven.plugins 40 | maven-compiler-plugin 41 | 42 | ${java.version} 43 | ${java.version} 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /spring-boot-multi-module-project/readme.rst: -------------------------------------------------------------------------------- 1 | Please follow the tutorial https://roytuts.com/spring-boot-multi-module-project/ 2 | -------------------------------------------------------------------------------- /spring-boot-multi-module-project/user-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 4.0.0 7 | 8 | 9 | com.roytuts 10 | spring-boot-multi-module-project 11 | 0.0.1-SNAPSHOT 12 | 13 | 14 | user-service 15 | 16 | 17 | UTF-8 18 | 19 | 20 | 21 | 22 | com.roytuts 23 | email-service 24 | ${project.version} 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /spring-boot-multi-module-project/user-service/src/main/java/com/roytuts/user/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.user.service; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import javax.annotation.PostConstruct; 7 | 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Service; 10 | 11 | import com.roytuts.email.service.EmailService; 12 | import com.roytuts.user.service.model.User; 13 | 14 | @Service 15 | public class UserService { 16 | 17 | @Autowired 18 | private EmailService emailService; 19 | 20 | private final List users = new ArrayList<>(); 21 | 22 | @PostConstruct 23 | public void init() { 24 | users.add(new User(1000, "Soumitra", "Roy", "contact@roytuts.com")); 25 | users.add(new User(1001, "Sudipto", "Bhowmick", "sudipto.bhowmick@email.com")); 26 | users.add(new User(1002, "Gautam", "Roy", "gautam.roy@email.com")); 27 | users.add(new User(1003, "Soumitra", "Sarkar", "contact@roytuts.com")); 28 | } 29 | 30 | public User getUserById(final int id) { 31 | return users.stream().filter(user -> user.getId() == id).findFirst().get(); 32 | } 33 | 34 | public void sendEmail(User user) { 35 | emailService.sendEmail(user.getEmail()); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /spring-boot-multi-module-project/user-service/src/main/java/com/roytuts/user/service/app/UserServiceApp.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.user.service.app; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication(scanBasePackages = "com.roytuts") 7 | public class UserServiceApp { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(UserServiceApp.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-boot-multi-module-project/user-service/src/main/java/com/roytuts/user/service/model/User.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.user.service.model; 2 | 3 | public class User { 4 | 5 | private int id; 6 | private String firstName; 7 | private String lastName; 8 | private String email; 9 | 10 | public User(int id, String firstName, String lastName, String email) { 11 | this.id = id; 12 | this.firstName = firstName; 13 | this.lastName = lastName; 14 | this.email = email; 15 | } 16 | 17 | public int getId() { 18 | return id; 19 | } 20 | 21 | public void setId(int id) { 22 | this.id = id; 23 | } 24 | 25 | public String getFirstName() { 26 | return firstName; 27 | } 28 | 29 | public void setFirstName(String firstName) { 30 | this.firstName = firstName; 31 | } 32 | 33 | public String getLastName() { 34 | return lastName; 35 | } 36 | 37 | public void setLastName(String lastName) { 38 | this.lastName = lastName; 39 | } 40 | 41 | public String getEmail() { 42 | return email; 43 | } 44 | 45 | public void setEmail(String email) { 46 | this.email = email; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /spring-boot-multi-module-project/web-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 4.0.0 7 | 8 | 9 | com.roytuts 10 | spring-boot-multi-module-project 11 | 0.0.1-SNAPSHOT 12 | 13 | 14 | web-service 15 | 16 | 17 | UTF-8 18 | 19 | 20 | 21 | 22 | com.roytuts 23 | user-service 24 | ${project.version} 25 | 26 | 27 | com.roytuts 28 | email-service 29 | ${project.version} 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /spring-boot-multi-module-project/web-service/src/main/java/com/roytuts/web/service/app/WebServiceApp.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.web.service.app; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication(scanBasePackages = "com.roytuts") 7 | public class WebServiceApp { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(WebServiceApp.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-boot-multi-module-project/web-service/src/main/java/com/roytuts/web/service/controller/WebRestController.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.web.service.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.http.HttpStatus; 5 | import org.springframework.http.ResponseEntity; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.PathVariable; 8 | import org.springframework.web.bind.annotation.PostMapping; 9 | import org.springframework.web.bind.annotation.RequestBody; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import com.roytuts.email.service.EmailService; 13 | import com.roytuts.user.service.UserService; 14 | import com.roytuts.user.service.model.User; 15 | 16 | @RestController 17 | public class WebRestController { 18 | 19 | @Autowired 20 | private EmailService emailService; 21 | 22 | @Autowired 23 | private UserService userService; 24 | 25 | @GetMapping("user/{id}") 26 | public User getUser(@PathVariable int id) { 27 | return userService.getUserById(id); 28 | } 29 | 30 | @PostMapping("user/") 31 | public ResponseEntity sendEmail(@RequestBody User user) { 32 | userService.sendEmail(user); 33 | return new ResponseEntity<>("Email Successfully sent", HttpStatus.OK); 34 | } 35 | 36 | @PostMapping("email/{toAddress}") 37 | public ResponseEntity sendEmail(@PathVariable String toAddress) { 38 | emailService.sendEmail(toAddress); 39 | return new ResponseEntity(HttpStatus.OK); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /spring-boot-mvc-jdbctemplate-crud/readme.rst: -------------------------------------------------------------------------------- 1 | Please follow the tutorial https://roytuts.com/spring-boot-mvc-with-maven/ -------------------------------------------------------------------------------- /spring-boot-mvc-jdbctemplate-crud/src/main/java/com/roytuts/spring/boot/mvc/jdbctemplate/crud/SpringBootMvcJdbcTemplateCrudApp.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.mvc.jdbctemplate.crud; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringBootMvcJdbcTemplateCrudApp { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringBootMvcJdbcTemplateCrudApp.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-boot-mvc-jdbctemplate-crud/src/main/java/com/roytuts/spring/boot/mvc/jdbctemplate/crud/dao/TeacherDao.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.mvc.jdbctemplate.crud.dao; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.jdbc.core.JdbcTemplate; 7 | import org.springframework.stereotype.Repository; 8 | import org.springframework.transaction.annotation.Transactional; 9 | 10 | import com.roytuts.spring.boot.mvc.jdbctemplate.crud.model.Teacher; 11 | import com.roytuts.spring.boot.mvc.jdbctemplate.crud.rowmapper.TeacherRowMapper; 12 | 13 | @Repository 14 | @Transactional 15 | public class TeacherDao { 16 | @Autowired 17 | private JdbcTemplate jdbcTemplate; 18 | 19 | public Teacher getTeacher(final int id) { 20 | Teacher teacher = jdbcTemplate.queryForObject("select * from teacher where id = ?", new TeacherRowMapper(), id); 21 | return teacher; 22 | } 23 | 24 | public List getTeachers() { 25 | List teachers = jdbcTemplate.query("select * from teacher", new TeacherRowMapper()); 26 | return teachers; 27 | } 28 | 29 | public void addTeacher(final Teacher teacher) { 30 | jdbcTemplate.update("insert into teacher(name, expertise) values(?, ?)", 31 | new Object[] { teacher.getName(), teacher.getExpertise() }); 32 | } 33 | 34 | public void updateTeacher(final Teacher teacher) { 35 | jdbcTemplate.update("update teacher set name = ?, expertise = ? where id = ?", 36 | new Object[] { teacher.getName(), teacher.getExpertise(), teacher.getId() }); 37 | } 38 | 39 | public void deleteTeacher(final int id) { 40 | jdbcTemplate.update("delete from teacher where id = ?", new Object[] { id }); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /spring-boot-mvc-jdbctemplate-crud/src/main/java/com/roytuts/spring/boot/mvc/jdbctemplate/crud/model/Teacher.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.mvc.jdbctemplate.crud.model; 2 | 3 | public class Teacher { 4 | 5 | private int id; 6 | private String name; 7 | private String expertise; 8 | 9 | public Teacher() { 10 | } 11 | 12 | public Teacher(int id, String name, String expertise) { 13 | this.id = id; 14 | this.name = name; 15 | this.expertise = expertise; 16 | } 17 | 18 | public int getId() { 19 | return id; 20 | } 21 | 22 | public void setId(int id) { 23 | this.id = id; 24 | } 25 | 26 | public String getName() { 27 | return name; 28 | } 29 | 30 | public void setName(String name) { 31 | this.name = name; 32 | } 33 | 34 | public String getExpertise() { 35 | return expertise; 36 | } 37 | 38 | public void setExpertise(String expertise) { 39 | this.expertise = expertise; 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | return "Teacher [id=" + id + ", name=" + name + ", expertise=" + expertise + "]"; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /spring-boot-mvc-jdbctemplate-crud/src/main/java/com/roytuts/spring/boot/mvc/jdbctemplate/crud/rowmapper/TeacherRowMapper.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.mvc.jdbctemplate.crud.rowmapper; 2 | 3 | import java.sql.ResultSet; 4 | import java.sql.SQLException; 5 | 6 | import org.springframework.jdbc.core.RowMapper; 7 | 8 | import com.roytuts.spring.boot.mvc.jdbctemplate.crud.model.Teacher; 9 | 10 | public class TeacherRowMapper implements RowMapper { 11 | 12 | @Override 13 | public Teacher mapRow(ResultSet rs, int row) throws SQLException { 14 | Teacher teacher = new Teacher(); 15 | teacher.setId(rs.getInt("id")); 16 | teacher.setName(rs.getString("name")); 17 | teacher.setExpertise(rs.getString("expertise")); 18 | return teacher; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /spring-boot-mvc-jdbctemplate-crud/src/main/java/com/roytuts/spring/boot/mvc/jdbctemplate/crud/service/TeacherService.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.mvc.jdbctemplate.crud.service; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import com.roytuts.spring.boot.mvc.jdbctemplate.crud.dao.TeacherDao; 9 | import com.roytuts.spring.boot.mvc.jdbctemplate.crud.model.Teacher; 10 | 11 | @Service 12 | public class TeacherService { 13 | 14 | @Autowired 15 | private TeacherDao teacherDao; 16 | 17 | public Teacher getTeacher(final int id) { 18 | return teacherDao.getTeacher(id); 19 | } 20 | 21 | public List getTeachers() { 22 | return teacherDao.getTeachers(); 23 | } 24 | 25 | public void addTeacher(final Teacher teacher) { 26 | teacherDao.addTeacher(teacher); 27 | } 28 | 29 | public void updateTeacher(final Teacher teacher) { 30 | teacherDao.updateTeacher(teacher); 31 | } 32 | 33 | public void deleteTeacher(final int id) { 34 | teacherDao.deleteTeacher(id); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /spring-boot-mvc-jdbctemplate-crud/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #database configuration 2 | spring.datasource.url=jdbc:mysql://localhost:3306/roytuts 3 | spring.datasource.username=root 4 | spring.datasource.password=root 5 | spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver 6 | 7 | #view resolver 8 | spring.mvc.view.prefix=/views/ 9 | spring.mvc.view.suffix=.jsp -------------------------------------------------------------------------------- /spring-boot-mvc-jdbctemplate-crud/src/main/webapp/views/add.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1"%> 3 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 4 | 5 | 6 | 7 | 8 | Spring Boot MVC JdbcTemplate CRUD Example 9 | 10 | 11 |

Spring Boot MVC JdbcTemplate CRUD Example - Add New Teacher

12 | 13 | ${msg} 14 | 15 |

Add User

16 |
18 | Name:

19 | Expertise: 20 |

21 |
22 | 23 | 24 | -------------------------------------------------------------------------------- /spring-boot-mvc-jdbctemplate-crud/src/main/webapp/views/teacher.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1"%> 3 | 4 | 5 | 6 | 7 | Spring Boot MVC JdbcTemplate CRUD Example 8 | 9 | 10 |

Spring Boot MVC JdbcTemplate CRUD Example - Teacher Details

11 | List of Teachers 12 |

13 | Id : ${teacher.id} 14 |
Name : ${teacher.name} 15 |
Expertise : ${teacher.expertise} 16 | 17 | 18 | -------------------------------------------------------------------------------- /spring-boot-mvc-jdbctemplate-crud/src/main/webapp/views/update.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1"%> 3 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 4 | 5 | 6 | 7 | 8 | Spring Boot MVC JdbcTemplate CRUD Example 9 | 10 | 11 |

Spring Boot MVC JdbcTemplate CRUD Example - Update Existing Teacher

12 | 13 | ${msg} 14 | 15 |

Update User

16 |
18 | Name:

20 | Expertise:

23 |
24 | 25 | 26 | -------------------------------------------------------------------------------- /spring-boot-profile-based-logging/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | 6 | com.roytuts 7 | spring-boot-profile-based-logging 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | 12 | UTF-8 13 | 19 14 | 19 15 | 16 | 17 | 18 | org.springframework.boot 19 | spring-boot-starter-parent 20 | 3.1.1 21 | 22 | 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter 27 | 28 | 29 | 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-maven-plugin 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /spring-boot-profile-based-logging/readme.rst: -------------------------------------------------------------------------------- 1 | Please follow the tutorial https://roytuts.com/spring-boot-profile-based-logging/ 2 | -------------------------------------------------------------------------------- /spring-boot-profile-based-logging/src/main/java/com/roytuts/spring/boot/profile/based/logging/SpringProfileBasedLoggingApp.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.profile.based.logging; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.boot.CommandLineRunner; 6 | import org.springframework.boot.SpringApplication; 7 | import org.springframework.boot.autoconfigure.SpringBootApplication; 8 | 9 | @SpringBootApplication 10 | public class SpringProfileBasedLoggingApp implements CommandLineRunner { 11 | 12 | private static final Logger LOG = LoggerFactory.getLogger(SpringProfileBasedLoggingApp.class); 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(SpringProfileBasedLoggingApp.class, args).close(); 16 | } 17 | 18 | @Override 19 | public void run(String... args) throws Exception { 20 | LOG.debug("Debug Message"); 21 | LOG.warn("Warn Message"); 22 | LOG.error("Error Message"); 23 | LOG.info("Info Message"); 24 | LOG.trace("Trace Message"); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /spring-boot-profile-based-logging/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.profiles.active=${spring.profiles.active} -------------------------------------------------------------------------------- /spring-boot-reactive-mongodb-crud/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.1.6.RELEASE' 4 | } 5 | 6 | repositories { 7 | mavenCentral() 8 | } 9 | 10 | dependencies { 11 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 12 | } 13 | } 14 | 15 | apply plugin: 'java' 16 | apply plugin: 'org.springframework.boot' 17 | 18 | sourceCompatibility = 1.8 19 | targetCompatibility = 1.8 20 | 21 | repositories { 22 | mavenCentral() 23 | } 24 | 25 | 26 | dependencies { 27 | implementation("org.springframework.boot:spring-boot-starter-webflux:${springBootVersion}") 28 | implementation("org.springframework.boot:spring-boot-starter-data-mongodb-reactive:${springBootVersion}") 29 | } 30 | -------------------------------------------------------------------------------- /spring-boot-reactive-mongodb-crud/readme.rst: -------------------------------------------------------------------------------- 1 | Please follow the tutorial https://roytuts.com/spring-boot-mongodb-functional-reactive-crud-example 2 | -------------------------------------------------------------------------------- /spring-boot-reactive-mongodb-crud/src/main/java/com/roytuts/spring/boot/reactive/mongodb/crud/app/ReactiveForexApp.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.reactive.mongodb.crud.app; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.domain.EntityScan; 6 | import org.springframework.data.mongodb.repository.config.EnableReactiveMongoRepositories; 7 | 8 | @EntityScan("com.roytuts.spring.boot.reactive.mongodb.crud.entity") 9 | @EnableReactiveMongoRepositories("com.roytuts.spring.boot.reactive.mongodb.crud.repository") 10 | @SpringBootApplication(scanBasePackages = "com.roytuts.spring.boot.reactive.mongodb.crud") 11 | public class ReactiveForexApp { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(ReactiveForexApp.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /spring-boot-reactive-mongodb-crud/src/main/java/com/roytuts/spring/boot/reactive/mongodb/crud/entity/Forex.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.reactive.mongodb.crud.entity; 2 | 3 | import org.springframework.data.annotation.Id; 4 | import org.springframework.data.mongodb.core.mapping.Document; 5 | 6 | @Document(collection = "forex") 7 | public class Forex { 8 | 9 | @Id 10 | private String id; 11 | private String fromCur; 12 | private String toCur; 13 | private Double rateCur; 14 | 15 | public Forex() { 16 | } 17 | 18 | public Forex(String fromCur, String toCur, Double rateCur) { 19 | this.fromCur = fromCur; 20 | this.toCur = toCur; 21 | this.rateCur = rateCur; 22 | } 23 | 24 | public Forex(String id, String fromCur, String toCur, Double rateCur) { 25 | this.id = id; 26 | this.fromCur = fromCur; 27 | this.toCur = toCur; 28 | this.rateCur = rateCur; 29 | } 30 | 31 | public String getId() { 32 | return id; 33 | } 34 | 35 | public void setId(String id) { 36 | this.id = id; 37 | } 38 | 39 | public String getFromCur() { 40 | return fromCur; 41 | } 42 | 43 | public void setFromCur(String fromCur) { 44 | this.fromCur = fromCur; 45 | } 46 | 47 | public String getToCur() { 48 | return toCur; 49 | } 50 | 51 | public void setToCur(String toCur) { 52 | this.toCur = toCur; 53 | } 54 | 55 | public Double getRateCur() { 56 | return rateCur; 57 | } 58 | 59 | public void setRateCur(Double rateCur) { 60 | this.rateCur = rateCur; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /spring-boot-reactive-mongodb-crud/src/main/java/com/roytuts/spring/boot/reactive/mongodb/crud/repository/ForexRepository.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.reactive.mongodb.crud.repository; 2 | 3 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 4 | 5 | import com.roytuts.spring.boot.reactive.mongodb.crud.entity.Forex; 6 | 7 | public interface ForexRepository extends ReactiveCrudRepository { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /spring-boot-reactive-mongodb-crud/src/main/java/com/roytuts/spring/boot/reactive/mongodb/crud/vo/ForexVo.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.reactive.mongodb.crud.vo; 2 | 3 | public class ForexVo { 4 | 5 | private String id; 6 | private String fromCur; 7 | private String toCur; 8 | private Double rateCur; 9 | 10 | public ForexVo() { 11 | } 12 | 13 | public ForexVo(String id, String fromCur, String toCur, Double rateCur) { 14 | this.id = id; 15 | this.fromCur = fromCur; 16 | this.toCur = toCur; 17 | this.rateCur = rateCur; 18 | } 19 | 20 | public String getId() { 21 | return id; 22 | } 23 | 24 | public void setId(String id) { 25 | this.id = id; 26 | } 27 | 28 | public String getFromCur() { 29 | return fromCur; 30 | } 31 | 32 | public void setFromCur(String fromCur) { 33 | this.fromCur = fromCur; 34 | } 35 | 36 | public String getToCur() { 37 | return toCur; 38 | } 39 | 40 | public void setToCur(String toCur) { 41 | this.toCur = toCur; 42 | } 43 | 44 | public Double getRateCur() { 45 | return rateCur; 46 | } 47 | 48 | public void setRateCur(Double rateCur) { 49 | this.rateCur = rateCur; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /spring-boot-reactive-mongodb-crud/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.data.mongodb.host=127.0.0.1 2 | spring.data.mongodb.port=27017 3 | spring.data.mongodb.database=roytuts 4 | 5 | spring.jackson.default-property-inclusion=NON_NULL -------------------------------------------------------------------------------- /spring-boot-reload-changes-without-server-restart/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 4.0.0 7 | 8 | com.roytuts 9 | spring-boot-reload-changes-without-server-restart 10 | 0.0.1-SNAPSHOT 11 | 12 | 13 | UTF-8 14 | 12 15 | 12 16 | 17 | 18 | 19 | org.springframework.boot 20 | spring-boot-starter-parent 21 | 2.4.5 22 | 23 | 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-web 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-devtools 33 | 34 | 35 | 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-maven-plugin 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /spring-boot-reload-changes-without-server-restart/readme.rst: -------------------------------------------------------------------------------- 1 | Please follow the tutorial https://roytuts.com/how-to-reload-changes-on-spring-boot-without-restart-server/ 2 | -------------------------------------------------------------------------------- /spring-boot-reload-changes-without-server-restart/src/main/java/com/roytuts/spring/boot/reload/changes/without/server/restart/GreetingController.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.reload.changes.without.server.restart; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | @RestController 7 | public class GreetingController { 8 | 9 | @GetMapping("/greet") 10 | public String greet() { 11 | return "Greetings, Welcome!"; 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /spring-boot-reload-changes-without-server-restart/src/main/java/com/roytuts/spring/boot/reload/changes/without/server/restart/SpringBootChangesWithoutRestartServerApp.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.reload.changes.without.server.restart; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringBootChangesWithoutRestartServerApp { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringBootChangesWithoutRestartServerApp.class, args); 11 | } 12 | 13 | } -------------------------------------------------------------------------------- /spring-boot-security-sso-oauth2/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.1.4.RELEASE' 4 | } 5 | repositories { 6 | mavenLocal() 7 | mavenCentral() 8 | } 9 | dependencies { 10 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 11 | } 12 | } 13 | 14 | apply plugin: 'java' 15 | apply plugin: 'org.springframework.boot' 16 | 17 | sourceCompatibility = 1.8 18 | targetCompatibility = 1.8 19 | 20 | repositories { 21 | mavenLocal() 22 | mavenCentral() 23 | } 24 | 25 | dependencies { 26 | compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}") 27 | compile("org.springframework.boot:spring-boot-starter-security:${springBootVersion}") 28 | compile("org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.1.4.RELEASE") 29 | compile('org.apache.tomcat.embed:tomcat-embed-jasper:8.5.14') 30 | compile('javax.servlet:jstl:1.2') 31 | } -------------------------------------------------------------------------------- /spring-boot-security-sso-oauth2/readme.rst: -------------------------------------------------------------------------------- 1 | Please follow the tutorial https://roytuts.com/spring-boot-security-example-single-sign-on-using-oauth-2/ 2 | -------------------------------------------------------------------------------- /spring-boot-security-sso-oauth2/src/main/java/com/roytuts/sso/oauth2/SsoOAuth2Application.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.sso.oauth2; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SsoOAuth2Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SsoOAuth2Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-boot-security-sso-oauth2/src/main/java/com/roytuts/sso/oauth2/config/SsoConfig.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.sso.oauth2.config; 2 | 3 | import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 6 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 7 | 8 | @Configuration 9 | @EnableOAuth2Sso 10 | public class SsoConfig extends WebSecurityConfigurerAdapter { 11 | 12 | @Override 13 | protected void configure(HttpSecurity http) throws Exception { 14 | http.authorizeRequests().antMatchers("/", "/user", "/login**", "/error**").permitAll().anyRequest() 15 | .authenticated().and().logout().logoutSuccessUrl("/").permitAll(); 16 | http.csrf().disable(); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /spring-boot-security-sso-oauth2/src/main/java/com/roytuts/sso/oauth2/config/SsoConfig_270.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.sso.oauth2.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.http.HttpStatus; 5 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 6 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 7 | import org.springframework.security.web.authentication.HttpStatusEntryPoint; 8 | 9 | @Configuration 10 | public class SsoConfig extends WebSecurityConfigurerAdapter { 11 | 12 | @Override 13 | protected void configure(HttpSecurity http) throws Exception { 14 | http.authorizeRequests(a -> a.antMatchers("/", "/error**", "/login**").permitAll().anyRequest().authenticated()) 15 | .exceptionHandling(e -> e.authenticationEntryPoint(new HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED))) 16 | .csrf(c -> c.disable()).logout(l -> l.logoutSuccessUrl("/").permitAll()).oauth2Login(); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /spring-boot-security-sso-oauth2/src/main/java/com/roytuts/sso/oauth2/controller/HomeController.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.sso.oauth2.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | 6 | @Controller 7 | public class HomeController { 8 | 9 | @GetMapping("/") 10 | public String home() { 11 | return "index"; 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /spring-boot-security-sso-oauth2/src/main/java/com/roytuts/sso/oauth2/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.sso.oauth2.controller; 2 | 3 | import java.security.Principal; 4 | 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | @RestController 9 | public class UserController { 10 | 11 | @GetMapping("/user") 12 | public Principal user(Principal principal) { 13 | return principal; 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-security-sso-oauth2/src/main/java/com/roytuts/sso/oauth2/controller/UserController_270.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.sso.oauth2.controller; 2 | 3 | import java.util.Collections; 4 | import java.util.Map; 5 | 6 | import org.springframework.security.core.annotation.AuthenticationPrincipal; 7 | import org.springframework.security.oauth2.core.user.OAuth2User; 8 | import org.springframework.web.bind.annotation.GetMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | @RestController 12 | public class UserController { 13 | 14 | @GetMapping("/user") 15 | public Map user(@AuthenticationPrincipal OAuth2User principal) { 16 | return Collections.singletonMap("name", principal.getAttribute("name")); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /spring-boot-security-sso-oauth2/src/main/java/com/roytuts/sso/oauth2/main/SsoOAuth2Application.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.sso.oauth2.main; 2 | import org.springframework.boot.SpringApplication; 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | 5 | @SpringBootApplication(scanBasePackages = "com.roytuts.sso.oauth2") 6 | public class SsoOAuth2Application { 7 | 8 | public static void main(String[] args) { 9 | SpringApplication.run(SsoOAuth2Application.class, args); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /spring-boot-security-sso-oauth2/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | #server port 2 | server: 3 | port: 9000 4 | 5 | #OAuth2 6 | security: 7 | oauth2: 8 | client: 9 | clientId: 10 | clientSecret: 11 | accessTokenUri: https://github.com/login/oauth/access_token 12 | userAuthorizationUri: https://github.com/login/oauth/authorize 13 | clientAuthenticationScheme: form 14 | resource: 15 | userInfoUri: https://api.github.com/user 16 | preferTokenInfo: false 17 | 18 | #view resolver 19 | spring: 20 | mvc: 21 | view: 22 | prefix: /view/ 23 | suffix: .jsp 24 | -------------------------------------------------------------------------------- /spring-boot-security-sso-oauth2/src/main/resources/application_270.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | security: 3 | oauth2: 4 | client: 5 | registration: 6 | github: 7 | client-id: 8 | client-secret: 9 | mvc: 10 | view: 11 | prefix: /view/ 12 | suffix: .jsp 13 | 14 | server: 15 | port: 9000 16 | -------------------------------------------------------------------------------- /spring-boot-security-sso-oauth2/src/main/webapp/view/index.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1"%> 3 | 4 | 5 | Spring Boot OAuth2 SSO Example 6 | 7 | 8 | 24 | 25 | 26 |
27 | Login With Github click here 28 |
29 | 35 | 36 | -------------------------------------------------------------------------------- /spring-boot-single-jar-war/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.6.7' 4 | } 5 | 6 | repositories { 7 | mavenCentral() 8 | } 9 | 10 | dependencies { 11 | classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}" 12 | } 13 | } 14 | 15 | plugins { 16 | id 'war' 17 | id 'java-library' 18 | id 'org.springframework.boot' version "${springBootVersion}" 19 | } 20 | 21 | /*jar { 22 | enabled = false 23 | //classifier = '' 24 | } 25 | 26 | bootJar { 27 | enabled = true 28 | }*/ 29 | 30 | war { 31 | enabled = false 32 | //classifier = '' 33 | } 34 | 35 | bootWar { 36 | enabled = true 37 | } 38 | 39 | sourceCompatibility = 11 40 | targetCompatibility = 11 41 | 42 | repositories { 43 | mavenCentral() 44 | } 45 | 46 | dependencies { 47 | implementation("org.springframework.boot:spring-boot-starter-web:${springBootVersion}") 48 | } 49 | 50 | -------------------------------------------------------------------------------- /spring-boot-single-jar-war/lib/src/main/java/spring/boot/single/jar/war/App.java: -------------------------------------------------------------------------------- 1 | package spring.boot.single.jar.war; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class App { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(App.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-boot-single-jar-war/lib/src/main/java/spring/boot/single/jar/war/AppRestController.java: -------------------------------------------------------------------------------- 1 | package spring.boot.single.jar.war; 2 | 3 | import org.springframework.http.HttpStatus; 4 | import org.springframework.http.ResponseEntity; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | @RestController 9 | public class AppRestController { 10 | 11 | @GetMapping("/") 12 | public ResponseEntity msg() { 13 | return new ResponseEntity("Welcome to REST API", HttpStatus.OK); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-single-jar-war/readme.rst: -------------------------------------------------------------------------------- 1 | Please follow the tutorial https://roytuts.com/generate-single-jar-or-war-in-spring-boot-app-using-gradle-build-tool/ 2 | -------------------------------------------------------------------------------- /spring-boot-use-jetty-instead-of-tomcat/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.4.4' 4 | } 5 | 6 | repositories { 7 | maven { 8 | url 'https://plugins.gradle.org/m2/' 9 | } 10 | } 11 | 12 | dependencies { 13 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 14 | } 15 | } 16 | 17 | plugins { 18 | id 'java-library' 19 | id 'org.springframework.boot' version "${springBootVersion}" 20 | } 21 | 22 | sourceCompatibility = 12 23 | targetCompatibility = 12 24 | 25 | repositories { 26 | mavenCentral() 27 | jcenter() 28 | } 29 | 30 | dependencies { 31 | implementation("org.springframework.boot:spring-boot-starter-web:${springBootVersion}") { 32 | exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat' 33 | } 34 | 35 | implementation "org.springframework.boot:spring-boot-starter-jetty" 36 | } -------------------------------------------------------------------------------- /spring-boot-use-jetty-instead-of-tomcat/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 4.0.0 7 | 8 | com.roytuts 9 | spring-boot-use-jetty-instead-of-tomcat 10 | 0.0.1-SNAPSHOT 11 | 12 | 13 | org.springframework.boot 14 | spring-boot-starter-parent 15 | 2.4.4 16 | 17 | 18 | 19 | UTF-8 20 | 12 21 | 12 22 | 23 | 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-web 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-tomcat 32 | 33 | 34 | 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter-jetty 39 | 40 | 41 | 42 | 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-maven-plugin 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /spring-boot-use-jetty-instead-of-tomcat/readme.rst: -------------------------------------------------------------------------------- 1 | please follow the tutorial https://roytuts.com/use-jetty-instead-of-tomcat-in-spring-boot-application/ 2 | 3 | pom.xml_3 is used for spring boot 3.x.y version 4 | -------------------------------------------------------------------------------- /spring-boot-use-jetty-instead-of-tomcat/src/main/java/com/roytuts/spring/boot/use/jetty/instead/of/tomcat/SpringBootJettyApp.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.use.jetty.instead.of.tomcat; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.http.HttpStatus; 6 | import org.springframework.http.ResponseEntity; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | @RestController 11 | @SpringBootApplication 12 | public class SpringBootJettyApp { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(SpringBootJettyApp.class, args); 16 | } 17 | 18 | @GetMapping("/") 19 | public ResponseEntity msg() { 20 | return new ResponseEntity("Using Jetty instead of Tomcat Server", HttpStatus.OK); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /spring-boot-web-app-form-validation/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.2.2.RELEASE' 4 | } 5 | repositories { 6 | mavenCentral() 7 | } 8 | dependencies { 9 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 10 | } 11 | } 12 | 13 | plugins { 14 | id 'java-library' 15 | id 'org.springframework.boot' version '2.2.2.RELEASE' 16 | } 17 | 18 | sourceCompatibility = 12 19 | targetCompatibility = 12 20 | 21 | repositories { 22 | mavenCentral() 23 | } 24 | 25 | dependencies { 26 | implementation("org.springframework.boot:spring-boot-starter-web:${springBootVersion}") 27 | implementation("org.springframework.boot:spring-boot-starter-thymeleaf:${springBootVersion}") 28 | implementation('org.hibernate:hibernate-validator:6.1.0.Final') 29 | implementation('org.apache.tomcat.embed:tomcat-embed-el:9.0.30') 30 | } -------------------------------------------------------------------------------- /spring-boot-web-app-form-validation/readme.rst: -------------------------------------------------------------------------------- 1 | Please follow the tutorial https://roytuts.com/form-validation-in-spring-boot-web-application/ 2 | -------------------------------------------------------------------------------- /spring-boot-web-app-form-validation/src/main/java/spring/boot/web/app/form/validation/SpringBootWebAppFormValidationApp.java: -------------------------------------------------------------------------------- 1 | package spring.boot.web.app.form.validation; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication(scanBasePackages = "spring.boot.web.app.form.validation") 7 | public class SpringBootWebAppFormValidationApp { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringBootWebAppFormValidationApp.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-boot-web-app-form-validation/src/main/java/spring/boot/web/app/form/validation/controller/WebAppController.java: -------------------------------------------------------------------------------- 1 | package spring.boot.web.app.form.validation.controller; 2 | 3 | import javax.validation.Valid; 4 | 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.validation.BindingResult; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.PostMapping; 9 | import org.springframework.web.bind.annotation.ResponseBody; 10 | 11 | import spring.boot.web.app.form.validation.dto.User; 12 | 13 | @Controller 14 | public class WebAppController { 15 | 16 | @GetMapping("/") 17 | public String showPage(User user) { 18 | return "form"; 19 | } 20 | 21 | @PostMapping("/") 22 | public String validateUser(@Valid User user, BindingResult bindingResult) { 23 | if (bindingResult.hasErrors()) { 24 | return "form"; 25 | } 26 | 27 | return "redirect:/success"; 28 | } 29 | 30 | @ResponseBody 31 | @GetMapping("/success") 32 | public String success() { 33 | return "Your form was successfully validated!"; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /spring-boot-whitelabel-error-page/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 4.0.0 7 | 8 | com.roytuts 9 | spring-boot-whitelabel-error-page 10 | 0.0.1-SNAPSHOT 11 | 12 | 13 | UTF-8 14 | 12 15 | 12 16 | 17 | 18 | 19 | org.springframework.boot 20 | spring-boot-starter-parent 21 | 2.4.4 22 | 23 | 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-web 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-thymeleaf 33 | 34 | 35 | 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-maven-plugin 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /spring-boot-whitelabel-error-page/readme.rst: -------------------------------------------------------------------------------- 1 | You can read tutorial https://roytuts.com/how-to-deal-with-whitelabel-error-page-in-spring-boot-applications/ -------------------------------------------------------------------------------- /spring-boot-whitelabel-error-page/src/main/java/com/roytuts/spring/boot/whitelabel/error/page/SpringBootWhiteLabelErrorPageApp.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.whitelabel.error.page; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | //@RestController 8 | @SpringBootApplication 9 | public class SpringBootWhiteLabelErrorPageApp { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SpringBootWhiteLabelErrorPageApp.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /spring-boot-whitelabel-error-page/src/main/resources/templates/error.html: -------------------------------------------------------------------------------- 1 |

Error Page

2 |

Application has encountered a problem. Please contact support ...

-------------------------------------------------------------------------------- /spring-depends-on-example/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.4.0' 4 | } 5 | 6 | repositories { 7 | maven { 8 | url 'https://plugins.gradle.org/m2/' 9 | } 10 | } 11 | 12 | dependencies { 13 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 14 | } 15 | } 16 | 17 | plugins { 18 | id 'java-library' 19 | id 'org.springframework.boot' version "${springBootVersion}" 20 | } 21 | 22 | sourceCompatibility = 12 23 | targetCompatibility = 12 24 | 25 | repositories { 26 | mavenCentral() 27 | jcenter() 28 | } 29 | 30 | dependencies { 31 | implementation("org.springframework.boot:spring-boot-starter:${springBootVersion}") 32 | } -------------------------------------------------------------------------------- /spring-depends-on-example/readme.rst: -------------------------------------------------------------------------------- 1 | You can read tutorial https://roytuts.com/depends-on-in-spring/ -------------------------------------------------------------------------------- /spring-depends-on-example/settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | * 4 | * The settings file is used to specify which projects to include in your build. 5 | * 6 | * Detailed information about configuring a multi-project build in Gradle can be found 7 | * in the user manual at https://docs.gradle.org/6.5.1/userguide/multi_project_builds.html 8 | */ 9 | 10 | rootProject.name = 'spring-depends-on-example' 11 | -------------------------------------------------------------------------------- /spring-depends-on-example/src/main/java/com/roytuts/spring/depends/on/example/BeanA.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.depends.on.example; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.DependsOn; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | @DependsOn(value = { "beanB", "beanC" }) 9 | public class BeanA { 10 | 11 | @Autowired 12 | private BeanB beanB; 13 | 14 | public BeanA() { 15 | System.out.println("Initializing BeanA"); 16 | } 17 | 18 | public BeanB getBeanB() { 19 | return beanB; 20 | } 21 | 22 | public void setBeanB(BeanB beanB) { 23 | this.beanB = beanB; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /spring-depends-on-example/src/main/java/com/roytuts/spring/depends/on/example/BeanB.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.depends.on.example; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | @Component 6 | public class BeanB { 7 | 8 | private String name; 9 | 10 | public BeanB() { 11 | System.out.println("BeanB is initialized."); 12 | } 13 | 14 | public String getName() { 15 | return name; 16 | } 17 | 18 | public void setName(String name) { 19 | this.name = name; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /spring-depends-on-example/src/main/java/com/roytuts/spring/depends/on/example/BeanC.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.depends.on.example; 2 | 3 | import org.springframework.context.annotation.DependsOn; 4 | import org.springframework.stereotype.Component; 5 | 6 | @Component 7 | @DependsOn(value = { "beanB" }) 8 | public class BeanC { 9 | 10 | public BeanC() { 11 | System.out.println("BeanC is initialized."); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /spring-depends-on-example/src/main/java/com/roytuts/spring/depends/on/example/SpringDependsOnApp.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.depends.on.example; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.boot.CommandLineRunner; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | 8 | @SpringBootApplication 9 | public class SpringDependsOnApp implements CommandLineRunner { 10 | 11 | @Autowired 12 | private BeanA beanA; 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(SpringDependsOnApp.class, args); 16 | } 17 | 18 | @Override 19 | public void run(String... args) throws Exception { 20 | beanA.getBeanB().setName("BeanB"); 21 | 22 | System.out.println(beanA.getBeanB().getName()); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /spring-file-upload/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.1.6.RELEASE' 4 | } 5 | repositories { 6 | mavenLocal() 7 | mavenCentral() 8 | } 9 | dependencies { 10 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 11 | } 12 | } 13 | 14 | apply plugin: 'java' 15 | apply plugin: 'org.springframework.boot' 16 | 17 | repositories { 18 | mavenLocal() 19 | mavenCentral() 20 | } 21 | 22 | dependencies { 23 | compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}") 24 | } -------------------------------------------------------------------------------- /spring-file-upload/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 4.0.0 7 | 8 | com.roytuts 9 | spring-file-upload 10 | 0.0.1-SNAPSHOT 11 | 12 | 13 | UTF-8 14 | 12 15 | 12 16 | 17 | 18 | 19 | org.springframework.boot 20 | spring-boot-starter-parent 21 | 2.5.0 22 | 23 | 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-web 28 | 29 | 30 | 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-maven-plugin 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /spring-file-upload/readme.rst: -------------------------------------------------------------------------------- 1 | You can read tutorial https://roytuts.com/upload-file-using-react-and-spring-boot/ -------------------------------------------------------------------------------- /spring-file-upload/src/main/java/com/roytuts/spring/fileupload/SpringFileUploadApp.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.fileupload; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication(scanBasePackages = "com.roytuts.spring.fileupload") 7 | public class SpringFileUploadApp { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringFileUploadApp.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-frontend-backend-project/.gitattributes: -------------------------------------------------------------------------------- 1 | # 2 | # https://help.github.com/articles/dealing-with-line-endings/ 3 | # 4 | # These are explicitly windows files and should use crlf 5 | *.bat text eol=crlf 6 | 7 | -------------------------------------------------------------------------------- /spring-frontend-backend-project/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore Gradle project-specific cache directory 2 | .gradle 3 | 4 | # Ignore Gradle build output directory 5 | build 6 | -------------------------------------------------------------------------------- /spring-frontend-backend-project/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.6.2' 4 | } 5 | 6 | repositories { 7 | mavenCentral() 8 | } 9 | 10 | dependencies { 11 | classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}" 12 | } 13 | } 14 | 15 | plugins { 16 | id 'java-library' 17 | id 'org.springframework.boot' version "${springBootVersion}" 18 | } 19 | 20 | sourceCompatibility = 16 21 | targetCompatibility = 16 22 | 23 | repositories { 24 | mavenCentral() 25 | } 26 | 27 | dependencies { 28 | implementation("org.springframework.boot:spring-boot-starter-web:${springBootVersion}") 29 | } 30 | 31 | task copyPublicResources(type: Copy) { 32 | from '../angular-ui/dist/angular-ui/' 33 | into 'src/main/resources/static/' 34 | } 35 | 36 | copyPublicResources.dependsOn(':angular-ui:buildApp') 37 | processResources.dependsOn(copyPublicResources) 38 | -------------------------------------------------------------------------------- /spring-frontend-backend-project/readme.rst: -------------------------------------------------------------------------------- 1 | Please follow the tutorial https://roytuts.com/integrate-angular-into-spring-boot-using-gradle/ -------------------------------------------------------------------------------- /spring-frontend-backend-project/settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | * 4 | * The settings file is used to specify which projects to include in your build. 5 | * 6 | * Detailed information about configuring a multi-project build in Gradle can be found 7 | * in the user manual at https://docs.gradle.org/7.4/userguide/multi_project_builds.html 8 | */ 9 | 10 | rootProject.name = 'spring-frontend-backend-project' 11 | 12 | include 'angular-ui' 13 | project(":angular-ui").projectDir = file("../angular-ui") 14 | -------------------------------------------------------------------------------- /spring-frontend-backend-project/src/main/java/spring/frontend/backend/project/App.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This Java source file was generated by the Gradle 'init' task. 3 | */ 4 | package spring.frontend.backend.project; 5 | 6 | import org.springframework.boot.SpringApplication; 7 | import org.springframework.boot.autoconfigure.SpringBootApplication; 8 | 9 | @SpringBootApplication 10 | public class App { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(App.class, args); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-frontend-backend-project/src/main/resources/static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/roytuts/spring-boot/695dc19ab9670384f946d5851c08396bad570e83/spring-frontend-backend-project/src/main/resources/static/favicon.ico -------------------------------------------------------------------------------- /spring-frontend-backend-project/src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | AngularUi 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /spring-frontend-backend-project/src/main/resources/static/runtime.b3427db387de8774.js: -------------------------------------------------------------------------------- 1 | (()=>{"use strict";var e,_={},i={};function n(e){var a=i[e];if(void 0!==a)return a.exports;var r=i[e]={exports:{}};return _[e](r,r.exports,n),r.exports}n.m=_,e=[],n.O=(a,r,t,f)=>{if(!r){var o=1/0;for(u=0;u=f)&&Object.keys(n.O).every(h=>n.O[h](r[l]))?r.splice(l--,1):(s=!1,f0&&e[u-1][2]>f;u--)e[u]=e[u-1];e[u]=[r,t,f]},n.n=e=>{var a=e&&e.__esModule?()=>e.default:()=>e;return n.d(a,{a}),a},n.d=(e,a)=>{for(var r in a)n.o(a,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:a[r]})},n.o=(e,a)=>Object.prototype.hasOwnProperty.call(e,a),(()=>{var e={666:0};n.O.j=t=>0===e[t];var a=(t,f)=>{var l,c,[u,o,s]=f,v=0;if(u.some(d=>0!==e[d])){for(l in o)n.o(o,l)&&(n.m[l]=o[l]);if(s)var b=s(n)}for(t&&t(f);v empDtos = employeeService.getEmpList(); 22 | 23 | model.addAttribute("orgChartDataList", empDtos); 24 | 25 | return "index"; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /spring-google-org-chart/src/main/java/com/roytuts/spring/google/orgchart/converter/EmpDtoEntityConverter.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.google.orgchart.converter; 2 | 3 | import java.util.List; 4 | import java.util.stream.Collectors; 5 | 6 | import com.roytuts.spring.google.orgchart.dto.EmpDto; 7 | import com.roytuts.spring.google.orgchart.entity.Employee; 8 | 9 | public final class EmpDtoEntityConverter { 10 | 11 | public static EmpDto getEmpDto(Employee employee) { 12 | return new EmpDto(employee.getId(), employee.getName(), employee.getDesignation(), employee.getManager()); 13 | } 14 | 15 | public static List getEmpDtoList(List employees) { 16 | return employees.stream().map(e -> getEmpDto(e)).collect(Collectors.toList()); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /spring-google-org-chart/src/main/java/com/roytuts/spring/google/orgchart/dto/EmpDto.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.google.orgchart.dto; 2 | 3 | public class EmpDto { 4 | 5 | private Integer id; 6 | 7 | private String name; 8 | 9 | private String designation; 10 | 11 | private String manager; 12 | 13 | public EmpDto() { 14 | } 15 | 16 | public EmpDto(Integer id, String name, String designation, String manager) { 17 | this.id = id; 18 | this.name = name; 19 | this.designation = designation; 20 | this.manager = manager; 21 | } 22 | 23 | public Integer getId() { 24 | return id; 25 | } 26 | 27 | public void setId(Integer id) { 28 | this.id = id; 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public void setName(String name) { 36 | this.name = name; 37 | } 38 | 39 | public String getDesignation() { 40 | return designation; 41 | } 42 | 43 | public void setDesignation(String designation) { 44 | this.designation = designation; 45 | } 46 | 47 | public String getManager() { 48 | return manager; 49 | } 50 | 51 | public void setManager(String manager) { 52 | this.manager = manager; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /spring-google-org-chart/src/main/java/com/roytuts/spring/google/orgchart/entity/Employee.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.google.orgchart.entity; 2 | 3 | import jakarta.persistence.Column; 4 | import jakarta.persistence.Entity; 5 | import jakarta.persistence.GeneratedValue; 6 | import jakarta.persistence.GenerationType; 7 | import jakarta.persistence.Id; 8 | import jakarta.persistence.Table; 9 | 10 | @Entity 11 | @Table(name = "emp") 12 | public class Employee { 13 | 14 | @Id 15 | @Column 16 | @GeneratedValue(strategy = GenerationType.IDENTITY) 17 | private Integer id; 18 | 19 | @Column 20 | private String name; 21 | 22 | @Column 23 | private String designation; 24 | 25 | @Column 26 | private String manager; 27 | 28 | public Integer getId() { 29 | return id; 30 | } 31 | 32 | public void setId(Integer id) { 33 | this.id = id; 34 | } 35 | 36 | public String getName() { 37 | return name; 38 | } 39 | 40 | public void setName(String name) { 41 | this.name = name; 42 | } 43 | 44 | public String getDesignation() { 45 | return designation; 46 | } 47 | 48 | public void setDesignation(String designation) { 49 | this.designation = designation; 50 | } 51 | 52 | public String getManager() { 53 | return manager; 54 | } 55 | 56 | public void setManager(String manager) { 57 | this.manager = manager; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /spring-google-org-chart/src/main/java/com/roytuts/spring/google/orgchart/repository/EmployeeRepository.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.google.orgchart.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import com.roytuts.spring.google.orgchart.entity.Employee; 6 | 7 | public interface EmployeeRepository extends JpaRepository { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /spring-google-org-chart/src/main/java/com/roytuts/spring/google/orgchart/service/EmployeeService.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.google.orgchart.service; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import com.roytuts.spring.google.orgchart.converter.EmpDtoEntityConverter; 9 | import com.roytuts.spring.google.orgchart.dto.EmpDto; 10 | import com.roytuts.spring.google.orgchart.entity.Employee; 11 | import com.roytuts.spring.google.orgchart.repository.EmployeeRepository; 12 | 13 | @Service 14 | public class EmployeeService { 15 | 16 | @Autowired 17 | private EmployeeRepository employeeRepository; 18 | 19 | public List getEmpList() { 20 | List employees = employeeRepository.findAll(); 21 | 22 | return EmpDtoEntityConverter.getEmpDtoList(employees); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /spring-google-org-chart/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver 2 | spring.datasource.url=jdbc:mysql://localhost/roytuts 3 | spring.datasource.username=root 4 | spring.datasource.password=root 5 | -------------------------------------------------------------------------------- /spring-google-org-chart/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Google Org Chart using Spring 6 | 7 | 40 | 41 | 42 | 43 |
44 |
45 |
46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /spring-google-pie-chart/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 4.0.0 7 | 8 | com.roytuts 9 | spring-google-pie-chart 10 | 0.0.1-SNAPSHOT 11 | 12 | 13 | UTF-8 14 | 19 15 | 19 16 | 17 | 18 | 19 | org.springframework.boot 20 | spring-boot-starter-parent 21 | 3.1.3 22 | 23 | 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-web 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-thymeleaf 33 | 34 | 35 | 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-maven-plugin 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /spring-google-pie-chart/readme.rst: -------------------------------------------------------------------------------- 1 | Please follow the tutorial https://roytuts.com/google-pie-chart-using-spring/ 2 | -------------------------------------------------------------------------------- /spring-google-pie-chart/src/main/java/com/roytuts/spring/google/pie/chart/GPieChartApp.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.google.pie.chart; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class GPieChartApp { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(GPieChartApp.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-google-pie-chart/src/main/java/com/roytuts/spring/google/pie/chart/controller/PieChartController.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.google.pie.chart.controller; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.ui.Model; 8 | import org.springframework.web.bind.annotation.GetMapping; 9 | 10 | import com.roytuts.spring.google.pie.chart.dao.PieChartDao.KeyValue; 11 | import com.roytuts.spring.google.pie.chart.service.PieChartService; 12 | 13 | @Controller 14 | public class PieChartController { 15 | 16 | @Autowired 17 | private PieChartService pieChartService; 18 | 19 | @GetMapping("/piechart") 20 | public String pieChart(Model model) { 21 | List pieDataList = pieChartService.getPieChartData(); 22 | 23 | model.addAttribute("pieDataList", pieDataList); 24 | 25 | return "index"; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /spring-google-pie-chart/src/main/java/com/roytuts/spring/google/pie/chart/dao/PieChartDao.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.google.pie.chart.dao; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class PieChartDao { 7 | 8 | private static final List pieDataList; 9 | 10 | static { 11 | pieDataList = new ArrayList(); 12 | pieDataList.add(new KeyValue("Russia", "17098242")); 13 | pieDataList.add(new KeyValue("Canada", "9984670")); 14 | pieDataList.add(new KeyValue("USA", "9826675")); 15 | pieDataList.add(new KeyValue("China", "9596961")); 16 | pieDataList.add(new KeyValue("Brazil", "8514877")); 17 | pieDataList.add(new KeyValue("Australia", "7741220")); 18 | pieDataList.add(new KeyValue("India", "3287263")); 19 | } 20 | 21 | public static List getPieDataList() { 22 | return pieDataList; 23 | } 24 | 25 | public static class KeyValue { 26 | String key; 27 | String value; 28 | 29 | public KeyValue(String key, String value) { 30 | this.key = key; 31 | this.value = value; 32 | } 33 | 34 | public String getKey() { 35 | return key; 36 | } 37 | 38 | public String getValue() { 39 | return value; 40 | } 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /spring-google-pie-chart/src/main/java/com/roytuts/spring/google/pie/chart/service/PieChartService.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.google.pie.chart.service; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.stereotype.Service; 6 | 7 | import com.roytuts.spring.google.pie.chart.dao.PieChartDao; 8 | import com.roytuts.spring.google.pie.chart.dao.PieChartDao.KeyValue; 9 | 10 | @Service 11 | public class PieChartService { 12 | 13 | public List getPieChartData() { 14 | return PieChartDao.getPieDataList(); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /spring-internationalization/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.1.8.RELEASE' 4 | } 5 | repositories { 6 | mavenCentral() 7 | } 8 | dependencies { 9 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 10 | } 11 | } 12 | 13 | apply plugin: 'java' 14 | apply plugin: 'org.springframework.boot' 15 | 16 | sourceCompatibility = 12 17 | targetCompatibility = 12 18 | 19 | repositories { 20 | mavenCentral() 21 | } 22 | 23 | dependencies { 24 | implementation("org.springframework.boot:spring-boot-starter-web:${springBootVersion}") 25 | implementation('org.apache.tomcat.embed:tomcat-embed-jasper:9.0.26') 26 | implementation('javax.servlet:jstl:1.2') 27 | } -------------------------------------------------------------------------------- /spring-internationalization/readme.rst: -------------------------------------------------------------------------------- 1 | Please follow the tutorial https://roytuts.com/spring-boot-internationalization-example/ 2 | -------------------------------------------------------------------------------- /spring-internationalization/src/main/java/com/roytuts/spring/internationalization/SpringInternationalizationApp.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.internationalization; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication(scanBasePackages = "com.roytuts.spring.internationalization") 7 | public class SpringInternationalizationApp { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringInternationalizationApp.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-internationalization/src/main/java/com/roytuts/spring/internationalization/controller/SpringInternationalizationController.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.internationalization.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | 6 | @Controller 7 | public class SpringInternationalizationController { 8 | 9 | @GetMapping("/") 10 | public String view() { 11 | return "i18n"; 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /spring-internationalization/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #view resolver 2 | spring.mvc.view.prefix=/views/ 3 | spring.mvc.view.suffix=.jsp -------------------------------------------------------------------------------- /spring-internationalization/src/main/resources/i18n/messages.properties: -------------------------------------------------------------------------------- 1 | msg=Internationalization Example in Spring Boot MVC 2 | welcome=Welcome to English Language 3 | chooseLang=Choose your language 4 | copyright=Copyright 5 | year=2014 - 2019 -------------------------------------------------------------------------------- /spring-internationalization/src/main/resources/i18n/messages_bn.properties: -------------------------------------------------------------------------------- 1 | msg=Spring Boot MVC \u098F \u0986\u09A8\u09CD\u09A4\u09B0\u09CD\u099C\u09BE\u09A4\u09BF\u0995\u09BE\u09AF\u09BC\u09A8 \u0989\u09A6\u09BE\u09B9\u09B0\u09A3 2 | welcome=\u09AC\u09BE\u0982\u09B2\u09BE \u09AD\u09BE\u09B7\u09BE \u09B8\u09CD\u09AC\u09BE\u0997\u09A4\u09AE 3 | chooseLang=\u0986\u09AA\u09A8\u09BE\u09B0 \u09AD\u09BE\u09B7\u09BE \u099A\u09AF\u09BC\u09A8 \u0995\u09B0\u09C1\u09A8 4 | copyright=\u0995\u09AA\u09BF\u09B0\u09BE\u0987\u099F 5 | year=\u09E8\u09E6\u09E7\u09EA - \u09E8\u09E6\u09E7\u09EF -------------------------------------------------------------------------------- /spring-internationalization/src/main/resources/i18n/messages_fr.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/roytuts/spring-boot/695dc19ab9670384f946d5851c08396bad570e83/spring-internationalization/src/main/resources/i18n/messages_fr.properties -------------------------------------------------------------------------------- /spring-internationalization/src/main/resources/i18n/messages_hi.properties: -------------------------------------------------------------------------------- 1 | msg=Spring Boot MVC \u092E\u0947\u0902 \u0905\u0902\u0924\u0930\u094D\u0930\u093E\u0937\u094D\u091F\u094D\u0930\u0940\u092F\u0915\u0930\u0923 \u0909\u0926\u093E\u0939\u0930\u0923 2 | welcome=\u0939\u093F\u0928\u094D\u0926\u0940 \u092D\u093E\u0937\u093E \u092E\u0947\u0902 \u0906\u092A\u0915\u093E \u0938\u094D\u0935\u093E\u0917\u0924 \u0939\u0948 3 | chooseLang=\u0905\u092A\u0928\u0940 \u092D\u093E\u0937\u093E \u091A\u0941\u0928\u0947\u0902 4 | copyright=\u0938\u0930\u094D\u0935\u093E\u0927\u093F\u0915\u093E\u0930 5 | year=\u0968\u0966\u0967\u096A - \u0968\u0966\u0967\u096F -------------------------------------------------------------------------------- /spring-internationalization/src/main/resources/i18n/messages_nl.properties: -------------------------------------------------------------------------------- 1 | msg=Internationalisering Voorbeeld in Spring Boot MVC 2 | welcome=Welkom bij Nederlandse Taal 3 | chooseLang=Kies uw taal 4 | copyright=Auteursrecht 5 | year=2014 - 2019 -------------------------------------------------------------------------------- /spring-jcache-support/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.1.8.RELEASE' 4 | } 5 | 6 | repositories { 7 | mavenLocal() 8 | mavenCentral() 9 | } 10 | 11 | dependencies { 12 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 13 | } 14 | } 15 | 16 | apply plugin: 'java' 17 | apply plugin: 'org.springframework.boot' 18 | 19 | sourceCompatibility = 12 20 | targetCompatibility = 12 21 | 22 | repositories { 23 | mavenLocal() 24 | mavenCentral() 25 | maven { 26 | url 'http://www.terracotta.org/download/reflector/releases' 27 | } 28 | } 29 | 30 | dependencies { 31 | implementation("org.springframework.boot:spring-boot-starter-web:${springBootVersion}") 32 | implementation("javax.cache:cache-api:1.1.1") 33 | implementation("org.ehcache:jcache:1.0.0") 34 | implementation("net.sf.ehcache:ehcache-ee:2.8.5") 35 | } -------------------------------------------------------------------------------- /spring-jcache-support/readme.rst: -------------------------------------------------------------------------------- 1 | Please follow the tutorial https://roytuts.com/spring-jcache-support/ 2 | -------------------------------------------------------------------------------- /spring-jcache-support/src/main/java/com/roytuts/spring/jcache/support/SpringJCacheApp.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.jcache.support; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.boot.CommandLineRunner; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | 8 | import com.roytuts.spring.jcache.support.model.Person; 9 | import com.roytuts.spring.jcache.support.repository.PersonRepository; 10 | 11 | @SpringBootApplication(scanBasePackages = "com.roytuts.spring.jcache.support") 12 | public class SpringJCacheApp implements CommandLineRunner { 13 | 14 | @Autowired 15 | private PersonRepository personRepository; 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(SpringJCacheApp.class, args); 19 | } 20 | 21 | @Override 22 | public void run(String... args) throws Exception { 23 | System.out.println("Fetching Person details"); 24 | Person person = personRepository.findPerson(String.valueOf(1)); 25 | System.out.println("Cached Person Info: " + person); 26 | personRepository.savePerson("1000", new Person("1000", "Soumitra Roy")); 27 | System.out.println("Saved Person Info in cache: " + personRepository.findPerson("1000")); 28 | personRepository.removePerson(new Person("1000", "Soumitra Roy")); 29 | System.out.println("Has Person Info removed from cache: " + (personRepository.findPerson("1000") != null)); 30 | personRepository.removeAllPersons(); 31 | System.out 32 | .println("Is there still any Person Info in the cache: " + (personRepository.findPerson("1") != null)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /spring-jcache-support/src/main/java/com/roytuts/spring/jcache/support/config/JCacheConfig.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.jcache.support.config; 2 | 3 | import javax.cache.CacheManager; 4 | 5 | import org.ehcache.jcache.JCacheCachingProvider; 6 | import org.ehcache.jcache.JCacheManager; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | 10 | @Configuration 11 | public class JCacheConfig { 12 | 13 | @Bean 14 | public CacheManager jCacheManager() { 15 | JCacheManager cacheManager = new JCacheManager(new JCacheCachingProvider(), ehcache(), null, null); 16 | return cacheManager; 17 | } 18 | 19 | private net.sf.ehcache.CacheManager ehcache() { 20 | net.sf.ehcache.CacheManager cacheManager = new net.sf.ehcache.CacheManager(); 21 | return cacheManager; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /spring-jcache-support/src/main/java/com/roytuts/spring/jcache/support/model/Person.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.jcache.support.model; 2 | 3 | import java.io.Serializable; 4 | 5 | public class Person implements Serializable { 6 | 7 | private static final long serialVersionUID = 1L; 8 | 9 | private String id; 10 | private String name; 11 | 12 | public Person(String id, String name) { 13 | this.id = id; 14 | this.name = name; 15 | } 16 | 17 | public String getId() { 18 | return id; 19 | } 20 | 21 | public String getName() { 22 | return name; 23 | } 24 | 25 | @Override 26 | public String toString() { 27 | return "Person [id=" + id + ", name=" + name + "]"; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /spring-jcache-support/src/main/resources/ehcache.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /spring-lookup-method-injection/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 4.0.0 7 | 8 | com.roytuts 9 | spring-lookup-method-injection 10 | 0.0.1-SNAPSHOT 11 | 12 | 13 | UTF-8 14 | 19 15 | 19 16 | 17 | 18 | 19 | org.springframework.boot 20 | spring-boot-starter-parent 21 | 3.1.1 22 | 23 | 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter 28 | 29 | 30 | 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-maven-plugin 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /spring-lookup-method-injection/readme.rst: -------------------------------------------------------------------------------- 1 | Please follow the tutorial https://roytuts.com/spring-singleton-bean-with-prototype-bean-lookup-method-injection/ 2 | -------------------------------------------------------------------------------- /spring-lookup-method-injection/src/main/java/com/roytuts/spring/lookup/method/injection/BeanA.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.lookup.method.injection; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.beans.factory.annotation.Lookup; 5 | import org.springframework.beans.factory.config.ConfigurableBeanFactory; 6 | import org.springframework.context.annotation.Scope; 7 | import org.springframework.stereotype.Component; 8 | 9 | @Component 10 | @Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON) 11 | public class BeanA { 12 | 13 | // @Autowired 14 | // private BeanB beanB; 15 | 16 | public void greetA() { 17 | System.out.println("beanB: " + beanB()); 18 | System.out.println("Msg: " + beanB().greetB()); 19 | } 20 | 21 | @Lookup 22 | public BeanB beanB() { 23 | return null; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /spring-lookup-method-injection/src/main/java/com/roytuts/spring/lookup/method/injection/BeanB.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.lookup.method.injection; 2 | 3 | import org.springframework.beans.factory.config.ConfigurableBeanFactory; 4 | import org.springframework.context.annotation.Scope; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) 9 | public class BeanB { 10 | 11 | public String greetB() { 12 | return "Greeting from B"; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /spring-lookup-method-injection/src/main/java/com/roytuts/spring/lookup/method/injection/SpringLookupMethodInjectionApp.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.lookup.method.injection; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.boot.CommandLineRunner; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | 8 | @SpringBootApplication 9 | public class SpringLookupMethodInjectionApp implements CommandLineRunner { 10 | 11 | @Autowired 12 | private BeanA beanA; 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(SpringLookupMethodInjectionApp.class, args); 16 | } 17 | 18 | @Override 19 | public void run(String... args) throws Exception { 20 | beanA.greetA(); 21 | beanA.greetA(); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /spring-mvc-autocomplete-input/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.1.7.RELEASE' 4 | } 5 | 6 | repositories { 7 | mavenLocal() 8 | mavenCentral() 9 | } 10 | 11 | dependencies { 12 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 13 | } 14 | } 15 | 16 | apply plugin: 'java' 17 | apply plugin: 'org.springframework.boot' 18 | 19 | sourceCompatibility = 12 20 | targetCompatibility = 12 21 | 22 | repositories { 23 | mavenLocal() 24 | mavenCentral() 25 | } 26 | 27 | dependencies { 28 | implementation("org.springframework.boot:spring-boot-starter-web:${springBootVersion}") 29 | compile('org.apache.tomcat.embed:tomcat-embed-jasper:9.0.22') 30 | compile('javax.servlet:jstl:1.2') 31 | } -------------------------------------------------------------------------------- /spring-mvc-autocomplete-input/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | com.roytuts 6 | spring-mvc-autocomplete-input 7 | 0.0.1-SNAPSHOT 8 | 9 | UTF-8 10 | 19 11 | 19 12 | 13 | 14 | org.springframework.boot 15 | spring-boot-starter-parent 16 | 3.0.5 17 | 18 | 19 | 20 | org.springframework.boot 21 | spring-boot-starter-web 22 | 23 | 24 | org.apache.tomcat.embed 25 | tomcat-embed-jasper 26 | 27 | 28 | javax.servlet 29 | jstl 30 | 1.2 31 | 32 | 33 | 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-maven-plugin 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /spring-mvc-autocomplete-input/readme.rst: -------------------------------------------------------------------------------- 1 | Please follow the tutorial https://roytuts.com/spring-boot-mvc-autocomplete/ 2 | -------------------------------------------------------------------------------- /spring-mvc-autocomplete-input/src/main/java/com/roytuts/spring/mvc/autocomplete/input/SpringMvcAutocompleteInputApp.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.mvc.autocomplete.input; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication(scanBasePackages = "com.roytuts.spring.mvc.autocomplete.input") 7 | public class SpringMvcAutocompleteInputApp { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringMvcAutocompleteInputApp.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-mvc-autocomplete-input/src/main/java/com/roytuts/spring/mvc/autocomplete/input/controller/HomeController.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.mvc.autocomplete.input.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | @Controller 7 | public class HomeController { 8 | 9 | @RequestMapping("/") 10 | public String home() { 11 | return "index"; 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /spring-mvc-autocomplete-input/src/main/java/com/roytuts/spring/mvc/autocomplete/input/rest/controller/AutoCompleteRestController.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.mvc.autocomplete.input.rest.controller; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.http.ResponseEntity; 8 | import org.springframework.web.bind.annotation.GetMapping; 9 | import org.springframework.web.bind.annotation.RequestParam; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import com.fasterxml.jackson.core.JsonProcessingException; 13 | import com.fasterxml.jackson.databind.ObjectMapper; 14 | import com.roytuts.spring.mvc.autocomplete.input.service.AutoCompleteService; 15 | 16 | @RestController 17 | public class AutoCompleteRestController { 18 | 19 | @Autowired 20 | AutoCompleteService autoCompleteService; 21 | 22 | @GetMapping("/search") 23 | public ResponseEntity doAutoComplete(@RequestParam("q") final String input) { 24 | List strings = autoCompleteService.doAutoComplete(input); 25 | 26 | ObjectMapper mapper = new ObjectMapper(); 27 | String resp = ""; 28 | 29 | try { 30 | resp = mapper.writeValueAsString(strings); 31 | } catch (JsonProcessingException e) { 32 | } 33 | 34 | return new ResponseEntity(resp, HttpStatus.OK); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /spring-mvc-autocomplete-input/src/main/java/com/roytuts/spring/mvc/autocomplete/input/service/AutoCompleteService.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.mvc.autocomplete.input.service; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.stereotype.Service; 6 | 7 | import com.roytuts.spring.mvc.autocomplete.input.dao.AutoCompleteDao; 8 | 9 | @Service 10 | public class AutoCompleteService { 11 | 12 | public List doAutoComplete(final String input) { 13 | return AutoCompleteDao.getStrings(input); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-mvc-autocomplete-input/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #view resolver 2 | spring.mvc.view.prefix=/views/ 3 | spring.mvc.view.suffix=.jsp -------------------------------------------------------------------------------- /spring-mvc-autocomplete-input/src/main/webapp/static/images/ui-anim_basic_16x16.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/roytuts/spring-boot/695dc19ab9670384f946d5851c08396bad570e83/spring-mvc-autocomplete-input/src/main/webapp/static/images/ui-anim_basic_16x16.gif -------------------------------------------------------------------------------- /spring-pdf-report-generation/ProductPdfReport.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/roytuts/spring-boot/695dc19ab9670384f946d5851c08396bad570e83/spring-pdf-report-generation/ProductPdfReport.pdf -------------------------------------------------------------------------------- /spring-pdf-report-generation/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.3.3.RELEASE' 4 | } 5 | 6 | repositories { 7 | mavenCentral() 8 | } 9 | 10 | dependencies { 11 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 12 | } 13 | } 14 | 15 | plugins { 16 | id 'java-library' 17 | id 'org.springframework.boot' version "${springBootVersion}" 18 | } 19 | 20 | sourceCompatibility = 12 21 | targetCompatibility = 12 22 | 23 | repositories { 24 | mavenCentral() 25 | } 26 | 27 | dependencies { 28 | implementation("org.springframework.boot:spring-boot-starter-web:${springBootVersion}") 29 | implementation("org.springframework.boot:spring-boot-starter-data-jpa:${springBootVersion}") 30 | 31 | implementation('com.itextpdf:itextpdf:5.5.13.1') 32 | 33 | implementation 'mysql:mysql-connector-java:8.0.21' 34 | 35 | //required for JDK 9 or above 36 | implementation 'javax.xml.bind:jaxb-api:2.4.0-b180830.0359' 37 | } -------------------------------------------------------------------------------- /spring-pdf-report-generation/readme.rst: -------------------------------------------------------------------------------- 1 | Please follow the tutorial https://roytuts.com/how-to-generate-pdf-report-from-mysql-database-in-spring-boot/ 2 | -------------------------------------------------------------------------------- /spring-pdf-report-generation/settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | * 4 | * The settings file is used to specify which projects to include in your build. 5 | * 6 | * Detailed information about configuring a multi-project build in Gradle can be found 7 | * in the user manual at https://docs.gradle.org/6.5.1/userguide/multi_project_builds.html 8 | */ 9 | 10 | rootProject.name = 'spring-pdf-report-generation' 11 | -------------------------------------------------------------------------------- /spring-pdf-report-generation/src/main/java/com/roytuts/pdf/report/generation/SpringPdfReportApp.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.pdf.report.generation; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringPdfReportApp { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringPdfReportApp.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-pdf-report-generation/src/main/java/com/roytuts/pdf/report/generation/repository/ProductRepository.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.pdf.report.generation.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import com.roytuts.pdf.report.generation.entity.Product; 6 | 7 | public interface ProductRepository extends JpaRepository { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /spring-pdf-report-generation/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #datasource 2 | spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver 3 | spring.datasource.url=jdbc:mysql://localhost/roytuts 4 | spring.datasource.username=root 5 | spring.datasource.password=root 6 | 7 | #disable schema generation from Hibernate 8 | spring.jpa.hibernate.ddl-auto=none -------------------------------------------------------------------------------- /spring-service-layer-bean-validation/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 4.0.0 7 | 8 | com.roytuts 9 | spring-service-layer-bean-validation 10 | 0.0.1-SNAPSHOT 11 | 12 | 13 | UTF-8 14 | 12 15 | 12 16 | 17 | 18 | 19 | org.springframework.boot 20 | spring-boot-starter-parent 21 | 2.4.5 22 | 23 | 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-web 28 | 29 | 30 | 31 | org.hibernate.validator 32 | hibernate-validator 33 | 34 | 35 | 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-maven-plugin 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /spring-service-layer-bean-validation/readme.rst: -------------------------------------------------------------------------------- 1 | You can go through the tutorial https://roytuts.com/spring-service-layer-bean-validation/ -------------------------------------------------------------------------------- /spring-service-layer-bean-validation/src/main/java/com/roytuts/spring/service/layer/bean/validation/SpringServiceLayerValidationApp.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.service.layer.bean.validation; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringServiceLayerValidationApp { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringServiceLayerValidationApp.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-service-layer-bean-validation/src/main/java/com/roytuts/spring/service/layer/bean/validation/rest/controller/GreetingRestController.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.service.layer.bean.validation.rest.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.PostMapping; 5 | import org.springframework.web.bind.annotation.RequestBody; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | import com.roytuts.spring.service.layer.bean.validation.service.GreetingService; 9 | import com.roytuts.spring.service.layer.bean.validation.vo.User; 10 | 11 | @RestController 12 | public class GreetingRestController { 13 | 14 | @Autowired 15 | private GreetingService service; 16 | 17 | @PostMapping("/greet") 18 | public Object getGreetingMsg(@RequestBody User user) { 19 | return service.getGreetingMsg(user); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /spring-service-layer-bean-validation/src/main/java/com/roytuts/spring/service/layer/bean/validation/service/GreetingService.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.service.layer.bean.validation.service; 2 | 3 | import java.util.Set; 4 | 5 | import javax.validation.ConstraintViolation; 6 | import javax.validation.ConstraintViolationException; 7 | import javax.validation.Valid; 8 | import javax.validation.Validator; 9 | 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Service; 12 | 13 | import com.roytuts.spring.service.layer.bean.validation.vo.User; 14 | 15 | @Service 16 | public class GreetingService { 17 | 18 | @Autowired 19 | private Validator validator; 20 | 21 | public String getGreetingMsg(@Valid User user) { 22 | Set> violations = validator.validate(user); 23 | 24 | if (!violations.isEmpty()) { 25 | StringBuilder sb = new StringBuilder(); 26 | for (ConstraintViolation constraintViolation : violations) { 27 | sb.append(constraintViolation.getMessage()); 28 | } 29 | 30 | throw new ConstraintViolationException("Error occurred: " + sb.toString(), violations); 31 | } 32 | 33 | return "Hi " + user.getName() + ", Good Morning!"; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /spring-service-layer-bean-validation/src/main/java/com/roytuts/spring/service/layer/bean/validation/vo/User.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.service.layer.bean.validation.vo; 2 | 3 | import javax.validation.constraints.NotEmpty; 4 | import javax.validation.constraints.NotNull; 5 | 6 | public class User { 7 | 8 | @NotEmpty(message = "Name is required field") 9 | @NotNull(message = "Name is required field") 10 | private String name; 11 | 12 | public String getName() { 13 | return name; 14 | } 15 | 16 | public void setName(String name) { 17 | this.name = name; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /spring-servletcontext-servletconfig/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.2.6.RELEASE' //to 2.4.4 4 | } 5 | repositories { 6 | mavenCentral() 7 | } 8 | dependencies { 9 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 10 | } 11 | } 12 | 13 | plugins { 14 | id 'java-library' 15 | id 'org.springframework.boot' version "${springBootVersion}" 16 | } 17 | 18 | sourceCompatibility = 12 19 | targetCompatibility = 12 20 | 21 | repositories { 22 | mavenCentral() 23 | } 24 | 25 | dependencies { 26 | implementation("org.springframework.boot:spring-boot-starter-web:${springBootVersion}") 27 | } -------------------------------------------------------------------------------- /spring-servletcontext-servletconfig/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 4.0.0 7 | 8 | com.roytuts 9 | spring-servletcontext-servletconfig 10 | 0.0.1-SNAPSHOT 11 | 12 | 13 | UTF-8 14 | 12 15 | 12 16 | 17 | 18 | 19 | org.springframework.boot 20 | spring-boot-starter-parent 21 | 2.4.4 22 | 23 | 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-web 28 | 29 | 30 | 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-maven-plugin 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /spring-servletcontext-servletconfig/readme.rst: -------------------------------------------------------------------------------- 1 | You can read tutorial at https://roytuts.com/how-to-get-servletcontext-and-servletconfig-object-in-a-spring-bean/ -------------------------------------------------------------------------------- /spring-servletcontext-servletconfig/src/main/java/com/roytuts/spring/servletcontext/servletconfig/SpringServletContextConfigApp.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.servletcontext.servletconfig; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringServletContextConfigApp { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringServletContextConfigApp.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-servletcontext-servletconfig/src/main/java/com/roytuts/spring/servletcontext/servletconfig/controller/SpringServletContextConfigController.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.servletcontext.servletconfig.controller; 2 | 3 | import javax.servlet.ServletConfig; 4 | import javax.servlet.ServletContext; 5 | 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.http.ResponseEntity; 8 | import org.springframework.stereotype.Controller; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.context.ServletConfigAware; 11 | import org.springframework.web.context.ServletContextAware; 12 | 13 | @Controller 14 | @RequestMapping("/controller") 15 | public class SpringServletContextConfigController implements ServletConfigAware, ServletContextAware { 16 | 17 | private ServletConfig servletConfig; 18 | private ServletContext servletContext; 19 | 20 | @Override 21 | public void setServletContext(ServletContext servletContext) { 22 | this.servletContext = servletContext; 23 | } 24 | 25 | @Override 26 | public void setServletConfig(ServletConfig servletConfig) { 27 | this.servletConfig = servletConfig; 28 | } 29 | 30 | @RequestMapping("/servlet/config") 31 | public ResponseEntity getServletConfig() { 32 | System.out.println("Servlet Config: " + servletConfig); 33 | return new ResponseEntity("Servlet Config: " + servletConfig, HttpStatus.OK); 34 | } 35 | 36 | @RequestMapping("/servlet/context") 37 | public ResponseEntity getServletContext() { 38 | return new ResponseEntity("Servlet Context: " + servletContext, HttpStatus.OK); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /spring-servletcontext-servletconfig/src/main/java/com/roytuts/spring/servletcontext/servletconfig/rest/controller/SpringServletContextConfigRestController.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.servletcontext.servletconfig.rest.controller; 2 | 3 | import javax.servlet.ServletConfig; 4 | import javax.servlet.ServletContext; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | @RestController 14 | @RequestMapping("/rest/controller") 15 | public class SpringServletContextConfigRestController { 16 | 17 | @Autowired 18 | private ServletConfig servletConfig; 19 | 20 | @Autowired 21 | private ServletContext servletContext; 22 | 23 | @GetMapping("/servlet/config") 24 | public ResponseEntity getServletConfig() { 25 | return new ResponseEntity("Servlet Config: " + servletConfig, HttpStatus.OK); 26 | } 27 | 28 | @GetMapping("/servlet/context") 29 | public ResponseEntity getServletContext() { 30 | return new ResponseEntity("Servlet Context: " + servletContext, HttpStatus.OK); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /spring-sse-push-notifications/readme.rst: -------------------------------------------------------------------------------- 1 | Please follow the tutorial https://roytuts.com/server-sent-events-spring-push-notifications/ 2 | -------------------------------------------------------------------------------- /spring-sse-push-notifications/spring-sse-push-notifications-client/SseClient.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Spring SSE Push Notifications 5 | 27 | 28 | 29 |
30 | 31 | -------------------------------------------------------------------------------- /spring-sse-push-notifications/spring-sse-push-notifications/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.1.8.RELEASE' to 2.4.4 4 | } 5 | 6 | repositories { 7 | } 8 | 9 | dependencies { 10 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 11 | } 12 | } 13 | 14 | plugins { 15 | id 'java-library' 16 | id 'org.springframework.boot' version "${springBootVersion}" 17 | } 18 | 19 | sourceCompatibility = 12 20 | targetCompatibility = 12 21 | 22 | repositories { 23 | mavenCentral() 24 | jcenter() 25 | } 26 | 27 | dependencies { 28 | implementation("org.springframework.boot:spring-boot-starter-web:${springBootVersion}") 29 | } -------------------------------------------------------------------------------- /spring-sse-push-notifications/spring-sse-push-notifications/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 4.0.0 7 | 8 | com.roytuts 9 | spring-sse-push-notifications 10 | 0.0.1-SNAPSHOT 11 | 12 | 13 | UTF-8 14 | 19 15 | 19 16 | 17 | 18 | org.springframework.boot 19 | spring-boot-starter-parent 20 | 3.1.0 21 | 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-web 26 | 27 | 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-maven-plugin 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /spring-sse-push-notifications/spring-sse-push-notifications/src/main/java/com/roytuts/spring/sse/push/notification/SpringSsePushNotificationApp.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.sse.push.notification; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringSsePushNotificationApp { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringSsePushNotificationApp.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-sse-push-notifications/spring-sse-push-notifications/src/main/java/com/roytuts/spring/sse/push/notification/controller/SsePushNotificationRestController.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.sse.push.notification.controller; 2 | 3 | import java.io.IOException; 4 | import java.util.List; 5 | import java.util.concurrent.CopyOnWriteArrayList; 6 | 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.http.HttpStatus; 9 | import org.springframework.http.ResponseEntity; 10 | import org.springframework.web.bind.annotation.CrossOrigin; 11 | import org.springframework.web.bind.annotation.GetMapping; 12 | import org.springframework.web.bind.annotation.RestController; 13 | import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; 14 | 15 | import com.roytuts.spring.sse.push.notification.service.SsePushNotificationService; 16 | 17 | @RestController 18 | @CrossOrigin(origins = "*") 19 | public class SsePushNotificationRestController { 20 | 21 | @Autowired 22 | SsePushNotificationService service; 23 | 24 | final List emitters = new CopyOnWriteArrayList<>(); 25 | 26 | @GetMapping("/notification") 27 | public ResponseEntity doNotify() throws InterruptedException, IOException { 28 | final SseEmitter emitter = new SseEmitter(); 29 | service.addEmitter(emitter); 30 | service.doNotify(); 31 | emitter.onCompletion(() -> service.removeEmitter(emitter)); 32 | emitter.onTimeout(() -> service.removeEmitter(emitter)); 33 | return new ResponseEntity<>(emitter, HttpStatus.OK); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /springboot-filter/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4.0.0 5 | 6 | com.roytuts 7 | springboot-filter 8 | 0.0.1-SNAPSHOT 9 | 10 | 11 | UTF-8 12 | 11 13 | 11 14 | 15 | 16 | 17 | org.springframework.boot 18 | spring-boot-starter-parent 19 | 2.6.7 20 | 21 | 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-web 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-devtools 31 | 32 | 33 | 34 | 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-maven-plugin 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /springboot-filter/readme.rst: -------------------------------------------------------------------------------- 1 | Please follow the tutorial https://roytuts.com/spring-boot-filters-example/ 2 | -------------------------------------------------------------------------------- /springboot-filter/src/main/java/com/roytuts/springboot/filter/App.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.springboot.filter; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class App { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(App.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-filter/src/main/java/com/roytuts/springboot/filter/AppRestController.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.springboot.filter; 2 | 3 | import org.springframework.http.HttpStatus; 4 | import org.springframework.http.ResponseEntity; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | @RestController 9 | public class AppRestController { 10 | 11 | @GetMapping("/") 12 | public ResponseEntity hello() { 13 | return new ResponseEntity("Hello", HttpStatus.OK); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springboot-filter/src/main/java/com/roytuts/springboot/filter/CacheControlFilter.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.springboot.filter; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.servlet.FilterChain; 6 | import javax.servlet.ServletException; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | 10 | import org.springframework.web.filter.RequestContextFilter; 11 | import org.springframework.web.util.ContentCachingRequestWrapper; 12 | import org.springframework.web.util.ContentCachingResponseWrapper; 13 | 14 | public class CacheControlFilter extends RequestContextFilter { 15 | 16 | @Override 17 | protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) 18 | throws ServletException, IOException { 19 | 20 | System.out.println("Cache Filter..."); 21 | 22 | ContentCachingRequestWrapper requestWrapper = new ContentCachingRequestWrapper(request); 23 | ContentCachingResponseWrapper responseWrapper = new ContentCachingResponseWrapper(response); 24 | 25 | filterChain.doFilter(requestWrapper, responseWrapper); 26 | 27 | setCacheHeaders(responseWrapper); 28 | 29 | responseWrapper.copyBodyToResponse(); 30 | } 31 | 32 | private void setCacheHeaders(ContentCachingResponseWrapper responseWrapper) { 33 | responseWrapper.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); 34 | responseWrapper.setHeader("Pragma", "no-cache"); // HTTP 1.0 35 | responseWrapper.setHeader("Expires", "0"); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /springboot-filter/src/main/java/com/roytuts/springboot/filter/CspControlFilter.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.springboot.filter; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.servlet.FilterChain; 6 | import javax.servlet.ServletException; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | 10 | import org.springframework.web.filter.RequestContextFilter; 11 | import org.springframework.web.util.ContentCachingRequestWrapper; 12 | import org.springframework.web.util.ContentCachingResponseWrapper; 13 | 14 | public class CspControlFilter extends RequestContextFilter { 15 | 16 | @Override 17 | protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) 18 | throws ServletException, IOException { 19 | 20 | System.out.println("CSP Filter..."); 21 | 22 | ContentCachingRequestWrapper requestWrapper = new ContentCachingRequestWrapper(request); 23 | ContentCachingResponseWrapper responseWrapper = new ContentCachingResponseWrapper(response); 24 | 25 | filterChain.doFilter(requestWrapper, responseWrapper); 26 | 27 | setCacheHeaders(responseWrapper); 28 | 29 | responseWrapper.copyBodyToResponse(); 30 | } 31 | 32 | private void setCacheHeaders(ContentCachingResponseWrapper responseWrapper) { 33 | responseWrapper.setHeader("Content-Security-Policy", "default-src 'self'"); 34 | responseWrapper.setHeader("Content-Security-Policy", "script-src 'self'"); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /springboot-filter/src/main/java/com/roytuts/springboot/filter/FilterConfig.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.springboot.filter; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import javax.servlet.Filter; 7 | 8 | import org.springframework.boot.web.servlet.FilterRegistrationBean; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.Configuration; 11 | 12 | @Configuration 13 | public class FilterConfig { 14 | 15 | @Bean 16 | public FilterRegistrationBean cacheControlFilter() { 17 | CacheControlFilter cacheControlFilter = new CacheControlFilter(); 18 | 19 | return createFilterRegistration(cacheControlFilter); 20 | } 21 | 22 | @Bean 23 | public FilterRegistrationBean cspControlFilter() { 24 | CspControlFilter cspControlFilter = new CspControlFilter(); 25 | 26 | return createFilterRegistration(cspControlFilter); 27 | } 28 | 29 | private FilterRegistrationBean createFilterRegistration(Filter filter) { 30 | FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(filter); 31 | 32 | List urlPatterns = new ArrayList<>(); 33 | urlPatterns.add("/*"); 34 | 35 | filterRegistrationBean.setUrlPatterns(urlPatterns); 36 | 37 | return filterRegistrationBean; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /springboot-main-springbootservletinitializer-junit/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4.0.0 5 | 6 | com.roytuts 7 | springboot-main-springbootservletinitializer-junit 8 | 0.0.1-SNAPSHOT 9 | 10 | 11 | UTF-8 12 | 11 13 | 11 14 | 15 | 16 | 17 | org.springframework.boot 18 | spring-boot-starter-parent 19 | 2.7.0 20 | 21 | 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-web 26 | 27 | 28 | 29 | junit 30 | junit 31 | test 32 | 33 | 34 | 35 | org.mockito 36 | mockito-core 37 | test 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-maven-plugin 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /springboot-main-springbootservletinitializer-junit/readme.rst: -------------------------------------------------------------------------------- 1 | Please follow the tutorial https://roytuts.com/how-to-write-junit-test-for-spring-boot-main-class/ 2 | -------------------------------------------------------------------------------- /springboot-main-springbootservletinitializer-junit/src/main/java/com/roytuts/springboot/main/springbootservletinitializer/junit/App.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.springboot.main.springbootservletinitializer.junit; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.builder.SpringApplicationBuilder; 6 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 7 | 8 | @SpringBootApplication 9 | //public class App { 10 | public class App extends SpringBootServletInitializer { 11 | 12 | @Override 13 | protected SpringApplicationBuilder configure(SpringApplicationBuilder springApplicationBuilder) { 14 | return springApplicationBuilder.sources(App.class); 15 | } 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(App.class, args); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /springboot-main-springbootservletinitializer-junit/src/test/java/com/roytuts/springboot/main/springbootservletinitializer/junit/AppTest.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.springboot.main.springbootservletinitializer.junit; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertTrue; 5 | 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.mockito.Mock; 9 | import org.mockito.Mockito; 10 | import org.mockito.junit.MockitoJUnitRunner; 11 | import org.springframework.boot.builder.SpringApplicationBuilder; 12 | 13 | @RunWith(MockitoJUnitRunner.class) 14 | public class AppTest { 15 | 16 | @Mock 17 | private SpringApplicationBuilder springApplicationBuilder; 18 | 19 | @Test 20 | public void testConfigure() { 21 | App app = new App(); 22 | 23 | Mockito.when(springApplicationBuilder.sources(App.class)).thenReturn(springApplicationBuilder); 24 | 25 | SpringApplicationBuilder result = app.configure(springApplicationBuilder); 26 | 27 | Mockito.verify(springApplicationBuilder).sources(App.class); 28 | 29 | assertEquals(springApplicationBuilder, result); 30 | } 31 | 32 | @Test 33 | public void testMain() { 34 | App.main(new String[] {}); 35 | assertTrue(true); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /websocket-on-spring-mongodb-functional-reactive/readme.rst: -------------------------------------------------------------------------------- 1 | Please follow the tutorial https://roytuts.com/websocket-on-spring-mongodb-reactive-programming 2 | -------------------------------------------------------------------------------- /websocket-on-spring-mongodb-functional-reactive/spring-boot-reactive-websocket-mogodb-client/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 |
9 |
10 | 11 | 12 |
13 |
14 | 15 |
16 |
17 | 18 |
19 |
20 | 21 |
22 |
23 | 24 | -------------------------------------------------------------------------------- /websocket-on-spring-mongodb-functional-reactive/spring-boot-reactive-websocket-mogodb/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.1.6.RELEASE' 4 | } 5 | 6 | repositories { 7 | mavenCentral() 8 | } 9 | 10 | dependencies { 11 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 12 | } 13 | } 14 | 15 | apply plugin: 'java' 16 | apply plugin: 'org.springframework.boot' 17 | 18 | sourceCompatibility = 1.8 19 | targetCompatibility = 1.8 20 | 21 | repositories { 22 | mavenCentral() 23 | } 24 | 25 | 26 | dependencies { 27 | implementation("org.springframework.boot:spring-boot-starter-webflux:${springBootVersion}") 28 | implementation("org.springframework.boot:spring-boot-starter-data-mongodb-reactive:${springBootVersion}") 29 | implementation('javax.websocket:javax.websocket-api:1.1') 30 | } -------------------------------------------------------------------------------- /websocket-on-spring-mongodb-functional-reactive/spring-boot-reactive-websocket-mogodb/src/main/java/com/roytuts/spring/boot/reactive/websocket/mogodb/app/SpringReactiveWebSocketMongoDbApp.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.reactive.websocket.mogodb.app; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.domain.EntityScan; 6 | import org.springframework.data.mongodb.repository.config.EnableReactiveMongoRepositories; 7 | 8 | @EntityScan("com.roytuts.spring.boot.reactive.websocket.mogodb.entity") 9 | @EnableReactiveMongoRepositories("com.roytuts.spring.boot.reactive.websocket.mogodb.repository") 10 | @SpringBootApplication(scanBasePackages = "com.roytuts.spring.boot.reactive.websocket.mogodb") 11 | public class SpringReactiveWebSocketMongoDbApp { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(SpringReactiveWebSocketMongoDbApp.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /websocket-on-spring-mongodb-functional-reactive/spring-boot-reactive-websocket-mogodb/src/main/java/com/roytuts/spring/boot/reactive/websocket/mogodb/entity/UserSubscription.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.reactive.websocket.mogodb.entity; 2 | 3 | import org.springframework.data.annotation.Id; 4 | import org.springframework.data.mongodb.core.mapping.Document; 5 | 6 | @Document(collection = "UserSubscription") 7 | public class UserSubscription { 8 | 9 | @Id 10 | private String id; 11 | private String email; 12 | 13 | public UserSubscription() { 14 | } 15 | 16 | public UserSubscription(String email) { 17 | this.email = email; 18 | } 19 | 20 | public String getId() { 21 | return id; 22 | } 23 | 24 | public void setId(String id) { 25 | this.id = id; 26 | } 27 | 28 | public String getEmail() { 29 | return email; 30 | } 31 | 32 | public void setEmail(String email) { 33 | this.email = email; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /websocket-on-spring-mongodb-functional-reactive/spring-boot-reactive-websocket-mogodb/src/main/java/com/roytuts/spring/boot/reactive/websocket/mogodb/handler/UserSubscriptionWebSocketHandler.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.reactive.websocket.mogodb.handler; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.beans.factory.config.ConfigurableBeanFactory; 5 | import org.springframework.context.annotation.Scope; 6 | import org.springframework.stereotype.Component; 7 | import org.springframework.web.reactive.socket.WebSocketHandler; 8 | import org.springframework.web.reactive.socket.WebSocketSession; 9 | 10 | import com.roytuts.spring.boot.reactive.websocket.mogodb.entity.UserSubscription; 11 | import com.roytuts.spring.boot.reactive.websocket.mogodb.repository.UserSubscriptionRepository; 12 | 13 | import reactor.core.publisher.Mono; 14 | 15 | @Component 16 | @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) 17 | public class UserSubscriptionWebSocketHandler implements WebSocketHandler { 18 | 19 | @Autowired 20 | private UserSubscriptionRepository repository; 21 | 22 | @Override 23 | public Mono handle(WebSocketSession session) { 24 | return session.send( 25 | session.receive().map(email -> new UserSubscription(email.getPayloadAsText())).flatMap(repository::save) 26 | .map(us -> session.textMessage(us.getEmail()))); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /websocket-on-spring-mongodb-functional-reactive/spring-boot-reactive-websocket-mogodb/src/main/java/com/roytuts/spring/boot/reactive/websocket/mogodb/repository/UserSubscriptionRepository.java: -------------------------------------------------------------------------------- 1 | package com.roytuts.spring.boot.reactive.websocket.mogodb.repository; 2 | 3 | import org.springframework.data.mongodb.repository.ReactiveMongoRepository; 4 | 5 | import com.roytuts.spring.boot.reactive.websocket.mogodb.entity.UserSubscription; 6 | 7 | public interface UserSubscriptionRepository extends ReactiveMongoRepository { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /websocket-on-spring-mongodb-functional-reactive/spring-boot-reactive-websocket-mogodb/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.data.mongodb.database=roytuts --------------------------------------------------------------------------------