├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── circle.yml ├── examples └── spring-capgemini-trace-sample │ ├── README.md │ ├── build.gradle │ └── src │ └── main │ ├── java │ └── com │ │ └── capgemini │ │ └── boot │ │ └── trace │ │ └── sample │ │ └── video │ │ ├── Application.java │ │ ├── client │ │ └── VideoSvcApi.java │ │ ├── controller │ │ └── VideoSvc.java │ │ └── repository │ │ ├── Video.java │ │ └── VideoRepository.java │ └── resources │ ├── addVideo.json │ ├── config │ └── application.properties │ └── data.sql ├── gradle ├── checkstyle.gradle ├── checkstyle │ ├── checkstyle.xml │ ├── required-header.txt │ └── suppressions.xml ├── codenarc.gradle ├── codenarc │ ├── codenarc.groovy │ └── codenarcTest.groovy ├── dependencies.gradle ├── javaModule.gradle ├── pom.gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle ├── spring-capgemini-core ├── build.gradle └── src │ ├── main │ └── java │ │ └── com │ │ └── capgemini │ │ └── boot │ │ └── core │ │ └── factory │ │ ├── EnableSettingBackedBeans.java │ │ ├── FactoryProcessorStrategy.java │ │ ├── SettingBackedBean.java │ │ ├── SettingBackedBeanFactory.java │ │ ├── SettingsResolver.java │ │ └── internal │ │ ├── DefaultAnnotationStrategy.java │ │ ├── DefaultExceptionFactory.java │ │ ├── ExceptionFactory.java │ │ ├── SettingBackedBeanFactoryPostProcessor.java │ │ ├── SettingBackedBeansConfiguration.java │ │ └── SpringBootSettingsResolver.java │ └── test │ └── groovy │ └── com │ └── capgemini │ └── boot │ └── core │ ├── SettingBackedBeanCreationSpec.groovy │ ├── TestApplication.java │ ├── TestFactory.java │ ├── TestSettingBackedBean.java │ └── TestSettings.java └── spring-capgemini-trace ├── build.gradle └── src ├── main └── java │ └── com │ └── capgemini │ └── boot │ └── trace │ ├── TraceLoggerConfiguration.java │ ├── TraceLoggerConfigurationUtils.java │ ├── TraceLoggerRegistrar.java │ ├── annotation │ ├── EnableTraceLogger.java │ └── Trace.java │ └── settings │ └── TraceLoggerSettings.java └── test └── groovy └── com └── capgemini └── boot └── trace ├── TestApplication.java ├── TraceLoggerConfigurationDisabledSpec.groovy ├── TraceLoggerConfigurationMessagesSpec.groovy ├── TraceLoggerConfigurationSpec.groovy ├── TraceLoggerRegistrarPointcutCrossoverSpec.groovy └── TraceLoggerRegistrarSpec.groovy /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .classpath 3 | .settings 4 | .project 5 | .gradle 6 | build/ 7 | bin/ 8 | out/ 9 | *.iml 10 | *.ipr 11 | *.iws 12 | *.idea 13 | gradle.properties -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Circle CI](https://circleci.com/gh/Capgemini/spring-boot-capgemini/tree/master.svg?style=svg&circle-token=9d20343e9806ad4e5ac6cae2b29c619ff8b28648)](https://circleci.com/gh/Capgemini/spring-boot-capgemini/tree/master) 2 | 3 | [![Gitter Chat](http://img.shields.io/badge/chat-online-brightgreen.svg)](https://gitter.im/Capgemini/spring-boot-capgemini) 4 | 5 | # Spring Boot - Capgemini 6 | 7 | Spring Boot Capgemini includes a number of Spring Boot Starters that we have found useful whilst building real world Spring Boot applications at Capgemini. 8 | 9 | Some of the Starters are integrations to technologies not currently provided out-of-the-box by Spring Boot, and are unlikely to ever be. Some may naturally fit as core features and will hopefully one day be subsumed by the core project. Others are just features we have found useful and hopefully you will too. 10 | 11 | ### Features 12 | * Trace logging - method entry and exit trace logging. 13 | 14 | ## Core Developers 15 | * [Russell Hart](https://github.com/rhart) 16 | * [Greg Wolverson] (https://github.com/gwolverson) 17 | * [Craig Williams] (https://github.com/craigwilliams84) 18 | * [Gareth Sullivan](https://github.com/sinsir) 19 | 20 | ##Contributors 21 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | import java.util.concurrent.atomic.AtomicBoolean 2 | import java.util.concurrent.locks.ReentrantLock 3 | 4 | apply from: "gradle/dependencies.gradle" 5 | 6 | buildscript { 7 | repositories { 8 | jcenter() 9 | } 10 | 11 | dependencies { 12 | classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.1.0" 13 | } 14 | } 15 | 16 | allprojects { 17 | apply plugin: 'com.jfrog.artifactory-upload' 18 | artifactoryPublish { 19 | skip true 20 | } 21 | 22 | group = "com.capgemini.spring" 23 | version = '0.9.1-SNAPSHOT' 24 | 25 | apply plugin: 'eclipse' 26 | apply plugin: 'idea' 27 | 28 | repositories { 29 | jcenter() 30 | } 31 | } 32 | 33 | ext { 34 | isSnapshot = version.endsWith("SNAPSHOT") 35 | 36 | publishedModules = [ 37 | "spring-capgemini-core", "spring-capgemini-trace" 38 | ].collect { project(it) } 39 | 40 | localRepoUrl = "${buildDir.toURI()}/localrepo" 41 | } 42 | 43 | subprojects { 44 | apply plugin: "base" 45 | apply plugin: 'java' 46 | 47 | tasks.withType(Upload).matching { it.name != "install" }.all { 48 | rootProject.subprojects { 49 | mustRunAfter tasks.matching { it instanceof VerificationTask } 50 | } 51 | } 52 | 53 | tasks.withType(Test) { 54 | allprojects { 55 | mustRunAfter tasks.withType(Checkstyle) 56 | } 57 | } 58 | 59 | tasks.withType(GroovyCompile) { 60 | allprojects { 61 | mustRunAfter tasks.withType(CodeNarc) 62 | } 63 | } 64 | 65 | apply plugin: 'maven' 66 | apply from: "${rootDir}/gradle/pom.gradle" 67 | } 68 | 69 | // Have to evaluate the children before setting up the publishing stuff so the dependencies are defined. 70 | evaluationDependsOnChildren() 71 | 72 | subprojects { 73 | if (project in publishedModules) { 74 | apply plugin: "com.jfrog.artifactory-upload" 75 | artifactoryPublish { task -> 76 | skip false 77 | rootProject.artifactory { 78 | contextUrl = 'http://oss.jfrog.org' 79 | publish { 80 | repository { 81 | repoKey = isSnapshot ? 'oss-snapshot-local' : 'oss-release-local' 82 | gradle.taskGraph.whenReady { taskGraph -> 83 | if (taskGraph.hasTask(task)) { 84 | username = bintrayUser 85 | password = bintrayApiKey 86 | } 87 | } 88 | } 89 | } 90 | } 91 | } 92 | 93 | assert description: "Project $project.path is published, must have a description" 94 | 95 | modifyPom { 96 | project { 97 | name project.name 98 | description project.description 99 | url "https://github.com/Capgemini/spring-boot-capgemini" 100 | licenses { 101 | license { 102 | name "The Apache Software License, Version 2.0" 103 | url "http://www.apache.org/licenses/LICENSE-2.0.txt" 104 | distribution "repo" 105 | } 106 | } 107 | scm { 108 | connection "scm:https://capgemini@github.com/capgemini/spring-boot-capgemini" 109 | developerConnection "scm:git@github.com:capgemini/spring-boot-capgemini.git" 110 | url "https://github.com/capgemini/spring-boot-capgemini" 111 | } 112 | developers { 113 | developer { 114 | id "capgemini" 115 | name "Team Capgemini" 116 | } 117 | } 118 | } 119 | } 120 | } else { 121 | 122 | } 123 | 124 | tasks.withType(Test) { 125 | testLogging { 126 | exceptionFormat "full" 127 | events "failed" 128 | } 129 | 130 | jvmArgs "-Xss320k" 131 | minHeapSize "312m" 132 | maxHeapSize "312m" 133 | } 134 | } 135 | 136 | // Maven POM generation is not thread safe, so serialize all the Upload tasks we can use `--parallel`. 137 | def lock = new ReentrantLock() 138 | def available = lock.newCondition() 139 | def busy = new AtomicBoolean() 140 | allprojects { 141 | tasks.withType(Upload) { uploadTask -> 142 | doFirst { 143 | lock.lock() 144 | while (busy.get()) { 145 | available.await() 146 | } 147 | busy.set(true) 148 | } 149 | } 150 | } 151 | gradle.taskGraph.afterTask { 152 | if (it instanceof Upload && lock.heldByCurrentThread) { 153 | busy.set(false) 154 | available.signal() 155 | lock.unlock() 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /circle.yml: -------------------------------------------------------------------------------- 1 | 2 | dependencies: 3 | cache_directories: 4 | - "~/.gradle" 5 | 6 | test: 7 | override: 8 | - ./gradlew clean build -i 9 | pre: 10 | - echo $BINTRAY_USER > gradle.properties 11 | - echo $BINTRAY_API_KEY >> gradle.properties 12 | post: 13 | - mkdir -p $CIRCLE_TEST_REPORTS/junit/ 14 | - find . -type f -regex ".*/build/test-results/.*xml" -exec cp {} $CIRCLE_TEST_REPORTS/junit/ \; 15 | 16 | deployment: 17 | master: 18 | branch: master 19 | commands: 20 | - ./gradlew artifactoryPublish -------------------------------------------------------------------------------- /examples/spring-capgemini-trace-sample/README.md: -------------------------------------------------------------------------------- 1 | Spring Boot Trace Sample 2 | ======================== 3 | 4 | Introduction 5 | ------------ 6 | 7 | This is a simple Video store application that allows users to 8 | 9 | * add a video to the store 10 | * retrieve all videos from the store 11 | * find a video by it's title 12 | 13 | A Video has the following attributes 14 | 15 | * id 16 | * name 17 | * url 18 | * duration; 19 | 20 | 21 | Design 22 | ------ 23 | 24 | ### REST API 25 | 26 | The Video store application is a Spring Boot Application, that as a Rest Controller class mapping the following URLs 27 | 28 | * `localhost:8080/video` (GET) - retrieve all videos from the store 29 | * `localhost:8080/video` (POST) - add a video to the store 30 | * `localhost:8080/video/find?title=MyVideo` (POST) - find all videos with title of "MyVideo" 31 | 32 | In order to add a video, the url must pass a JSON payload containing the Video information. 33 | 34 | `src/main/resources/addVideo.json` is a json file containing a single Video entry. Use the 'curl' command to send a HTTP POST command containing the json defined in this file to the specified url. 35 | 36 | `curl -H "Content-Type: application/json" --data @addVideo.json http://localhost:8080/video` 37 | 38 | ### JPA Repository 39 | 40 | The application defines a repository that extends the Spring "CrudRepository". The gradle build file defines a H2 database, Spring Boot discovers it and and runs an in memory h2 database within the application. The `VideoRepository` interface defines the application's interface to the database. There is no implementation of the `VideoRepository` in the project, Spring dynamically creates the implementation when it discovers the `@Repository` annotated interface. 41 | 42 | On Spring Boot startup Spring JDBC finds, and executes the `data.sql` file located in the `src/main/resources` directory. This file populates the repository with 3 Video entries. 43 | 44 | ### Trace starter 45 | 46 | The video applications gradle build file declares the `spring-boot-trace` spring boot starter as a dependency. 47 | 48 | This allows the use of the `@EnableTraceLogging` annotation to state that this application can be configured to trace entry/exit/exception points of public methods, defined by configuration. 49 | 50 | Configuration 51 | ------------- 52 | 53 | ### Logging configuration 54 | 55 | The `spring-boot-trace` spring boot starter logs at `TRACE` level, so the default `LogBack` logger used by the Video Spring Boot application must be configured to capture logs at this `TRACE` level. This can be configured in the configuration file in `src/main/resources/config/application.properties`, as follows 56 | 57 | `logging.level.com.capgemini.boot.trace.sample.video.controller.VideoSvc=TRACE` - configures `TRACE` logging for only the VideoSvc class 58 | 59 | OR 60 | 61 | `logging.level.com.capgemini.boot.trace.sample.video.*=TRACE` - configures `TRACE` logging for all classes in the `com.capgemini.boot.trace.sample.video package` and its subpackages. 62 | 63 | 64 | ### Trace configuration 65 | 66 | To enable trace logging, the following attribute in the `application.properties` file must be set to true 67 | 68 | `trace-logging.enabled=true` 69 | 70 | If, as in the video application example, the target object to be trace logged implements an interface, you must forces the use of CGLIB rather than JDK dynamic proxies by setting the following property in the `application.properties` file 71 | 72 | `spring.aop.proxyTargetClass=true` 73 | 74 | see [spring documentation](http://docs.spring.io/spring/docs/2.5.x/reference/aop.html#aop-proxying) for more information 75 | 76 | ### Trace pointcut configuration 77 | 78 | The methods to be traced by the `spring-boot-trace` starter, are defined by AOP pointcut expressions in the following format in the `application.properties` file 79 | 80 | `trace-logging.pointcut.NAME=execution(* com.capgemini.boot.trace.sample.video.controller.VideoSvc.*(..)) 81 | 82 | where NAME is used to differentiate pointcuts. 83 | 84 | The Spring AOP pointcut expression language is defined, with examples, at the following [Spring documentation](http://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html#aop-pointcuts-examples) 85 | 86 | The video application uses 87 | 88 | `trace-logging.pointcut.videoSvc=execution(* com.capgemini.boot.trace.sample.video.controller.VideoSvc.*(..))` 89 | 90 | which means that all public methods of the VideoSvc class are trace logged 91 | 92 | The following examples enables tracing of all public methods in VideoSvc class that take a String parameter - i.e the method "Collection