{"id":20455262,"url":"https://github.com/pouyapouryaie/basicfeaturesforspringproject","last_synced_at":"2026-02-17T10:04:10.483Z","repository":{"id":149312764,"uuid":"397212388","full_name":"PouyaPouryaie/basicFeaturesForSpringProject","owner":"PouyaPouryaie","description":"This Repo contain basic features for develop application base on spring boot. some of this features is  RestApi, cache, hibernate, mapper, test, docker and .....","archived":false,"fork":false,"pushed_at":"2025-01-16T02:26:27.000Z","size":262,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-08T17:41:13.458Z","etag":null,"topics":["ehcache-spring","ehcache3","internationalization","jasypt-password","log4j2","mapstruct","spock-framework","spring","spring-configuration","spring-test","spring-validation","spring-web","springboot2","swagger-api","task-scheduler","testcontainers"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PouyaPouryaie.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-08-17T10:37:03.000Z","updated_at":"2025-01-15T01:53:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"5ae8c7b6-3bd8-4e21-ac06-f18a4377012f","html_url":"https://github.com/PouyaPouryaie/basicFeaturesForSpringProject","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"purl":"pkg:github/PouyaPouryaie/basicFeaturesForSpringProject","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PouyaPouryaie%2FbasicFeaturesForSpringProject","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PouyaPouryaie%2FbasicFeaturesForSpringProject/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PouyaPouryaie%2FbasicFeaturesForSpringProject/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PouyaPouryaie%2FbasicFeaturesForSpringProject/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PouyaPouryaie","download_url":"https://codeload.github.com/PouyaPouryaie/basicFeaturesForSpringProject/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PouyaPouryaie%2FbasicFeaturesForSpringProject/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29539974,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-17T08:11:05.436Z","status":"ssl_error","status_checked_at":"2026-02-17T08:09:38.860Z","response_time":100,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ehcache-spring","ehcache3","internationalization","jasypt-password","log4j2","mapstruct","spock-framework","spring","spring-configuration","spring-test","spring-validation","spring-web","springboot2","swagger-api","task-scheduler","testcontainers"],"created_at":"2024-11-15T11:18:22.781Z","updated_at":"2026-02-17T10:04:10.452Z","avatar_url":"https://github.com/PouyaPouryaie.png","language":"Java","readme":"# BasicFeaturesForSpringProject\n\nThis project, implement instance of basic feature, \u003cbr\u003e you maybe want use for App base on Spring-boot \u003cbr\u003e\n\n### Note for upgrade to 2.4.X \n1) for active profile config: \u003cbr\u003e\nfor before 2.4.x you can activate profile in pom file and add \u003cb\u003e@spring.profiles.active@\u003c/b\u003e in application.properties \u003cbr\u003e\nand then properties apply in project base on profile that active. \u003cbr\u003e\nfor 2.4.x or above\n    - if you want to use same as old solution you must add ```spring.config.use-legacy-processing=true``` in application.properties\n    - if you want to migrate in new approach please check https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-Config-Data-Migration-Guide\n\n\n## Features: \n- spring-web\n- spring-jpa\n    - with custom configuration for PersistenceContext\n- Connection-pool\n    - HikariCp with Possibility of customization\n- Ehcache \n    - customize cache config and implement log for cache\n- Log4j2 \n    - logging and config log-message\n- Exception management\n- MapStruct\n    - mapper tools for map view to entity and vice-versa\n- Validation handler\n    - use annotation for validation\n    - use log for validation error\n    - define your validation and use for model\n- TestUtils\n  - generator data with javaFaker\n  - unit and integration test with \u003cb\u003eSpock\u003c/b\u003e Framework\n  - SwaggerAPI for show detail of Rest endpoint\n  - TestContainer use for run db as dockerImage for test, and after that image is stop\n- decoupling layer\n    - controller, service and repository layer for easy extend\n- flexible search\n    - use CriteriaQuery and CriteriaBuilder for search base on Entity\n- jasypt\n    - use for encrypt password and added to config file, then decrypted pass in runtime\n- Jobs\n    - use Spring TaskScheduler for run jobs \n- Message Source\n    - use message-source to define message in one file and use in whole project\n    - use locale for config language of app for show message from different source\n\n## Run guide\n### Run for develop and debug: \u003cbr\u003e\n1 - check active profile on dev \u003cbr\u003e\n2 - run postgre sql on 5432 and create database myapp \u003cbr\u003e\n3 - run app \u003cbr\u003e\n4 - app.generator.enabled properties set to true, when you want to generate fake data \u003cbr\u003e\n\n### Run as docker image: \u003cbr\u003e\n1 - check active profile on docker and package project \u003cbr\u003e\n2 - create image from app: \u003cb\u003edocker build -t springapp:latest . \u003c/b\u003e\n\u003cbr\u003e\n3 - run app: \u003cb\u003edocker compose run\u003c/b\u003e \u003cbr\u003e\n\n\n## Features Explain: \n### exception feature\n\n1 - use AppException for define your own error Exception \u003cbr\u003e\n2 - user HttpExceptionModel for define your own error message and show to client \u003cbr\u003e\n3 - use HttpErrorCode for unifying error code in project \u003cbr\u003e\n\n### validation feature\n\n1 - create your own validation type \u003cbr\u003e\n2 - define your own validation process for entity \u003cbr\u003e\n3 - use \"@validator\" annotation on field of entity for validate \u003cbr\u003e\n4 - log for validation and save error-message in log file \u003cbr\u003e\n\n### search v2 base on NativeQuery feature\n1 - query clause, order for result and pagination can define in client Request as queryString and handle in AbstractController \u003cbr\u003e\n2 - buildNativeQueryCondition method in Utils class use for create native query base on request queryString \u003cbr\u003e\n3 - dynamic order and direction for sort data handle in daoRepository \u003cbr\u003e\n4 - more detail about search feature, see searchEngineV2.drawio \u003cbr\u003e \n5 - sample rest search request: \u003cbr\u003e\n```http://localhost:9090/api/v2/user/search?firstName=h\u0026orderBy=firstName_asc, gender_desc\u0026page=1\u0026size=5```\n\n### search v3 base on CriteriaBuilder feature\n1 - query clause, order for result and pagination can define in client Request as queryString and handle in AbstractController \u003cbr\u003e\n2 - define Quartet from javaTuples lib that use for define name of field from client, name of field in model, sqlOperation and sqlCondition \u003cbr\u003e\n3 - define Sort.Order object of spring with getSortOrderFromPagedQuery method to use for order by Clause\u003cbr\u003e\n4 - then use getUserQueryWithCriteriaBuilder in userRepository for create query and get Result\u003cbr\u003e\n5 - sample rest search request: \u003cbr\u003e\n```http://localhost:9090/api/v2/user/search?firstName=h\u0026orderBy=firstName_asc, gender_desc\u0026page=1\u0026size=5```\n\n### test feature\n1 - generate sample data baseOn model with javaFaker \u003cbr\u003e\n2 - Spock framework use for test \u003cbr\u003e\n3 - sample test define in test directory with groovy language \u003cbr\u003e\n4 - Swagger Api for show details of endpoints \u003cbr\u003e\n5 - In order to change swagger url, you must be change springdoc.swagger-ui.path property in application-dev.properties \u003cbr\u003e\n6 - TestContainer for run db as dockerImage, properties config exist in application-test.properties \u003cbr\u003e\n\n### dataSource feature\n1 - choose between use simpleDataSource or HikariCp datasource \u003cbr\u003e\n2 - you can customize properties for dataSource in application.properties\n3 - you can define batch config for use execute batch for update and insert to db\n\n### database password generator\nif you want to use encrypt password in config file for access database, you must follow below statement. \u003cbr\u003e\n\n1 - use jasypt for generate encrypted database password with secret-key\n~~~\njava -cp jasypt-1.9.3.jar org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI input={password} password={secret-key} algorithm=PBEWithMD5AndTripleDES\n~~~\n2 - add output into application.properties \u003cbr\u003e\nnote: I use '\u003cb\u003eENC()\u003cb\u003e' as convention to use check password for decrypt or not. \u003cbr\u003e\n\nnormal datasource:\n~~~\ndemo.datasource.password=\"ENC({output})\"\n~~~\nhikari datasource:\n~~~\nhikari.dataSource.password=\"ENC({output})\"\n~~~\n3 - run program and add in program environment secret-key:\n~~~\n--jasypt.encryptor.password={secret-key}\n~~~\n\n### Jobs Run Tool\n1) define class implement Runnable in order to execute job base on schedule \n2) define bean (AlertServiceJob) in BeanConfig class for your jobs\n3) define trigger time in properties ```(ex: app.jobs.alertServiceJob=0 */1 * ? * *)``` file\n4) @EnableScheduling on SpringApp\n\nnotice: that name of bean in BeanConfig must be equal with name of key in properties file.\n\n### Message Source\n1) define LocaleConfig to implement  Base config to define messageSource\n   1) how load message source (ex: loadMessageSource method in LocaleConfig class)\n   2) how define bean for use message source for specific category (ex: errorCodeSourceDesc method in LocaleConfig class)\n   3) how define config for resolve locale (ex: localeResolver method in LocaleConfig class)\n2) add message key from message-source bundle into code (ex: SampleExceptionType enum class)\n3) the code is written use locale by header, and you should set Accept-Language in request header\n4) define message and messageContainer for use to send identical messageResponse for error or normal message\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpouyapouryaie%2Fbasicfeaturesforspringproject","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpouyapouryaie%2Fbasicfeaturesforspringproject","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpouyapouryaie%2Fbasicfeaturesforspringproject/lists"}