Skip to content

Commit fdc48aa

Browse files
authored
Merge pull request #29 from spt-development/feature/spring-boot-3.2.5-upgrade
Feature/spring boot 3.2.5 upgrade
2 parents b83f29d + 4e2d3b7 commit fdc48aa

File tree

20 files changed

+387
-56
lines changed

20 files changed

+387
-56
lines changed

.github/maven-settings.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
</activation>
2424
<properties>
2525
<gpg.executable>gpg</gpg.executable>
26-
<gpg.passphrase>${env.GPG_PASSPHRASE}</gpg.passphrase>
2726
</properties>
2827
</profile>
2928
</profiles>

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
persist-credentials: false
1414

1515
- name: Cache local Maven repository
16-
uses: actions/cache@v3
16+
uses: actions/cache@v4
1717
with:
1818
path: ~/.m2/repository
1919
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
@@ -68,7 +68,7 @@ jobs:
6868
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
6969
GIT_HUB_USERNAME: ${{ secrets.GIT_HUB_USERNAME }}
7070
GIT_HUB_TOKEN: ${{ secrets.GIT_HUB_TOKEN }}
71-
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
71+
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
7272

7373
- name: Create GitHub release
7474
id: create_release

.github/workflows/owasp.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
shell: bash
1717

1818
- name: Restore cached Maven dependencies
19-
uses: actions/cache/restore@v3
19+
uses: actions/cache/restore@v4
2020
with:
2121
path: ~/.m2/repository
2222
# Using datetime in cache key as OWASP database may change, without the pom changing
@@ -36,7 +36,7 @@ jobs:
3636

3737
# Want the Maven dependencies to be cached even if the build fails as we want the OWASP database cached, regardless of whether vulnerabilities are found or not
3838
- name: Cache Maven dependencies
39-
uses: actions/cache/save@v3
39+
uses: actions/cache/save@v4
4040
if: always()
4141
with:
4242
path: ~/.m2/repository

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
[![build_status](https://github.com/spt-development/spt-development-logging-spring/actions/workflows/build.yml/badge.svg)](https://github.com/spt-development/spt-development-logging-spring/actions)
1212

1313
A library for adding logging (at the start, end and on exception) to public methods of classes annotated with
14-
`@RestController`, `@Service` or `@Repository` or methods annotated with `@JmsListener`.
14+
`@RestController`, `@Service` or `@Repository` or methods annotated with `@JmsListener` or methods of sub-classes
15+
of `org.springframework.dao.support.DaoSupport`.
1516

1617
Usage
1718
=====
@@ -21,6 +22,10 @@ Register the Aspects as Spring Beans manually or by adding the
2122
starter to your project's pom.
2223

2324
```java
25+
import com.spt.development.logging.spring.DaoSupportLogger;
26+
27+
import java.beans.BeanProperty;
28+
2429
@Bean
2530
public RestControllerLogger restControllerLogger() {
2631
return new RestControllerLogger();
@@ -40,8 +45,18 @@ public ServiceLogger serviceLogger() {
4045
public RepositoryLogger repositoryLogger() {
4146
return new RepositoryLogger();
4247
}
48+
49+
@Bean
50+
public DaoSupportLogger daoSupportLogger() {
51+
return new DaoSupportLogger();
52+
}
4353
```
4454

55+
*NOTE* The `DaoSupportLogger` will result in warnings such as the following being logged by `CglibAopProxy`:
56+
57+
`Unable to proxy interface-implementing method [public final void org.springframework.dao.support.DaoSupport.afterPropertiesSet() throws java.lang.IllegalArgumentException,org.springframework.beans.factory.BeanInitializationException]
58+
because it is marked as final, consider using interface-based JDK proxies instead.`
59+
4560
Building locally
4661
================
4762

config/pmd/rulesets/spt-default-rules.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919
<rule ref="category/java/bestpractices.xml/DoubleBraceInitialization" />
2020
<rule ref="category/java/bestpractices.xml/ForLoopCanBeForeach" />
2121
<rule ref="category/java/bestpractices.xml/LiteralsFirstInComparisons" />
22-
<rule ref="category/java/bestpractices.xml/LooseCoupling" />
22+
<rule ref="category/java/bestpractices.xml/LooseCoupling">
23+
<properties>
24+
<property name="allowedTypes" value="org.springframework.core.annotation.AnnotationAttributes" />
25+
</properties>
26+
</rule>
2327
<rule ref="category/java/bestpractices.xml/MethodReturnsInternalArray" />
2428
<rule ref="category/java/bestpractices.xml/MissingOverride" />
2529
<rule ref="category/java/bestpractices.xml/OneDeclarationPerLine" />
@@ -101,7 +105,7 @@
101105
<rule ref="category/java/design.xml/SwitchDensity" />
102106
<rule ref="category/java/design.xml/UseUtilityClass">
103107
<properties>
104-
<property name="violationSuppressXPath" value="//ClassOrInterfaceDeclaration/preceding-sibling::Annotation/MarkerAnnotation/Name[@Image='SpringBootApplication']" />
108+
<property name="violationSuppressXPath" value=".[pmd-java:hasAnnotation('org.springframework.boot.autoconfigure.SpringBootApplication')]" />
105109
</properties>
106110
</rule>
107111
<rule ref="category/java/design.xml/UselessOverridingMethod" />
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## New Features
2+
3+
* Added logging for public methods of classes that extend `org.springframework.dao.support.DaoSupport`.
4+
5+
## Dependencies
6+
7+
* Aligned dependencies with [Spring Boot 3.2.5](https://github.com/spring-projects/spring-boot/releases/tag/v3.2.5)

pom.xml

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>com.spt-development</groupId>
55
<artifactId>spt-development-logging-spring</artifactId>
6-
<version>3.0.17-SNAPSHOT</version>
6+
<version>3.1.0-SNAPSHOT</version>
77

88
<name>logging-spring</name>
99
<description>A very simple library for getting/setting the current correlation ID, utilising ThreadLocal.</description>
@@ -38,13 +38,13 @@
3838
<spt-cid.version>2.0.14</spt-cid.version>
3939

4040
<!-- Dependency versions, matched to Spring Boot -->
41-
<aspectj.version>1.9.21</aspectj.version>
41+
<aspectj.version>1.9.22</aspectj.version>
4242
<httpcore5.version>5.2.4</httpcore5.version>
43-
<slf4j.version>2.0.12</slf4j.version>
44-
<spring.version>6.1.5</spring.version>
43+
<slf4j.version>2.0.13</slf4j.version>
44+
<spring.version>6.1.6</spring.version>
4545

4646
<!-- Test dependency versions -->
47-
<spt-development-test.version>3.1.5</spt-development-test.version>
47+
<spt-development-test.version>3.1.6</spt-development-test.version>
4848

4949
<!-- Test dependency versions, matched to Spring Boot -->
5050
<hamcrest.version>2.2</hamcrest.version>
@@ -55,30 +55,31 @@
5555
<!-- Plugin versions -->
5656
<build-helper-maven-plugin.version>3.5.0</build-helper-maven-plugin.version>
5757
<checkstyle-maven-plugin.version>3.3.1</checkstyle-maven-plugin.version>
58-
<dependency-check-maven.version>9.0.10</dependency-check-maven.version>
59-
<jacoco-maven-plugin.version>0.8.11</jacoco-maven-plugin.version>
58+
<dependency-check-maven.version>9.1.0</dependency-check-maven.version>
59+
<jacoco-maven-plugin.version>0.8.12</jacoco-maven-plugin.version>
6060
<license-maven-plugin.version>2.4.0</license-maven-plugin.version>
6161
<maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
6262
<maven-dependency-plugin.version>3.6.1</maven-dependency-plugin.version>
6363
<maven-enforcer-plugin.version>3.4.1</maven-enforcer-plugin.version>
64-
<maven-gpg-plugin.version>3.2.1</maven-gpg-plugin.version>
64+
<maven-gpg-plugin.version>3.2.4</maven-gpg-plugin.version>
6565
<maven-javadoc-plugin.version>3.6.3</maven-javadoc-plugin.version>
6666
<maven-jxr-plugin.version>3.3.2</maven-jxr-plugin.version>
67-
<maven-pmd-plugin.version>3.21.2</maven-pmd-plugin.version>
67+
<maven-pmd-plugin.version>3.22.0</maven-pmd-plugin.version>
6868
<maven-release-plugin.version>3.0.1</maven-release-plugin.version>
69-
<maven-scm-plugin.version>2.0.1</maven-scm-plugin.version>
70-
<maven-source-plugin.version>3.3.0</maven-source-plugin.version>
69+
<maven-scm-plugin.version>2.1.0</maven-scm-plugin.version>
70+
<maven-source-plugin.version>3.3.1</maven-source-plugin.version>
7171
<maven-surefire-plugin.version>3.2.5</maven-surefire-plugin.version>
7272
<nexus-staging-plugin.version>1.6.13</nexus-staging-plugin.version>
73-
<pitest-maven.version>1.15.8</pitest-maven.version>
74-
<spotbugs.version>4.8.3.1</spotbugs.version>
73+
<pitest-maven.version>1.16.0</pitest-maven.version>
74+
<spotbugs.version>4.8.4.0</spotbugs.version>
7575
<versions-maven-plugin.version>2.16.2</versions-maven-plugin.version>
7676

7777
<!-- Plugin dependencies -->
78-
<checkstyle.version>10.14.2</checkstyle.version>
78+
<checkstyle.version>10.15.0</checkstyle.version>
7979
<findbugs-slf4j-bug-pattern.version>1.5.0</findbugs-slf4j-bug-pattern.version>
8080
<findbugs-sec-bug-pattern.version>1.12.0</findbugs-sec-bug-pattern.version>
8181
<pitest-junit5-plugin.version>1.2.1</pitest-junit5-plugin.version>
82+
<pmd.version>7.1.0</pmd.version>
8283
</properties>
8384

8485
<dependencyManagement>
@@ -216,6 +217,28 @@
216217
<plugin>
217218
<artifactId>maven-pmd-plugin</artifactId>
218219
<version>${maven-pmd-plugin.version}</version>
220+
<dependencies>
221+
<dependency>
222+
<groupId>net.sourceforge.pmd</groupId>
223+
<artifactId>pmd-core</artifactId>
224+
<version>${pmd.version}</version>
225+
</dependency>
226+
<dependency>
227+
<groupId>net.sourceforge.pmd</groupId>
228+
<artifactId>pmd-java</artifactId>
229+
<version>${pmd.version}</version>
230+
</dependency>
231+
<dependency>
232+
<groupId>net.sourceforge.pmd</groupId>
233+
<artifactId>pmd-javascript</artifactId>
234+
<version>${pmd.version}</version>
235+
</dependency>
236+
<dependency>
237+
<groupId>net.sourceforge.pmd</groupId>
238+
<artifactId>pmd-jsp</artifactId>
239+
<version>${pmd.version}</version>
240+
</dependency>
241+
</dependencies>
219242
</plugin>
220243
<plugin>
221244
<artifactId>maven-source-plugin</artifactId>
@@ -439,7 +462,7 @@
439462
Any classes / packages excluded here, must have specific rules for them below,
440463
with reasons.
441464
-->
442-
<exclude>com.spt.development.audit.spring.security.AuthenticationAdapterFactory</exclude>
465+
<exclude>com.spt.development.logging.spring.LoggerAspect</exclude>
443466
</excludes>
444467
</rule>
445468
<rule>
@@ -448,15 +471,12 @@
448471
<limit>
449472
<counter>LINE</counter>
450473
<value>COVEREDRATIO</value>
451-
<minimum>0.82</minimum>
474+
<minimum>0.97</minimum>
452475
</limit>
453476
</limits>
454477
<includes>
455-
<!--
456-
Difficult to force the ClassNotFoundException when checking if authentication
457-
object is an instance of OAuth2Authentication
458-
-->
459-
<include>com.spt.development.audit.spring.security.AuthenticationAdapterFactory</include>
478+
<!-- Placeholder method for pointcut does not need to be explicitly covered by tests -->
479+
<include>com.spt.development.logging.spring.LoggerAspect</include>
460480
</includes>
461481
</rule>
462482
</rules>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.spt.development.logging.spring;
2+
3+
import org.aspectj.lang.ProceedingJoinPoint;
4+
import org.aspectj.lang.annotation.Around;
5+
import org.aspectj.lang.annotation.Aspect;
6+
7+
/**
8+
* Logs calls to all public methods belonging to classes with the <code>org.springframework.stereotype.Repository</code>
9+
* annotation.
10+
*/
11+
@Aspect
12+
public class DaoSupportLogger extends LoggerAspect {
13+
14+
/**
15+
* Creates a new instance of the logger aspect. The log statements added by the aspect will include the current
16+
* correlation ID; see {@link DaoSupportLogger#DaoSupportLogger(boolean)} to disable this behaviour.
17+
*/
18+
public DaoSupportLogger() {
19+
this(true);
20+
}
21+
22+
/**
23+
* Creates a new instance of the logger aspect.
24+
*
25+
* @param includeCorrelationIdInLogs a flag to determine whether the correlation ID should be explicitly included
26+
* in the log statements added by the aspect.
27+
*/
28+
public DaoSupportLogger(final boolean includeCorrelationIdInLogs) {
29+
super(includeCorrelationIdInLogs);
30+
}
31+
32+
/**
33+
* Outputs DEBUG level logging when a public method belonging to a class, extending
34+
* <code>org.springframework.dao.support.DaoSupport</code> is called and when it returns (without
35+
* exception). If TRACE level logging is enabled and the method has a non-<code>void</code> return type, the
36+
* return value will be included in the logging. For example:
37+
*
38+
* <pre>
39+
* [40872057-a1b6-4fdd-bce1-7882929bbce6] MyDao.read(4)
40+
* ...
41+
* [40872057-a1b6-4fdd-bce1-7882929bbce6] MyDao.read Returned: MyEntity(id=4, name=test)
42+
* </pre>
43+
*
44+
* @param point the aspect join point required for implementing a {@link Around} aspect.
45+
*
46+
* @return the value returned from the method logged.
47+
*
48+
* @throws Throwable thrown if the method logged throws a {@link Throwable}.
49+
*/
50+
@Override
51+
@Around("execution(public * org.springframework.dao.support.DaoSupport+.*(..)) && !loggingDisabled()")
52+
public Object log(final ProceedingJoinPoint point) throws Throwable {
53+
return super.log(point);
54+
}
55+
}

src/main/java/com/spt/development/logging/spring/JmsListenerLogger.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ public JmsListenerLogger(final boolean includeCorrelationIdInLogs) {
4949
* @throws Throwable thrown if the method logged throws a {@link Throwable}.
5050
*/
5151
@Override
52-
@Around("@annotation(org.springframework.jms.annotation.JmsListener) "
53-
+ "&& !@annotation(com.spt.development.logging.NoLogging) "
54-
+ "&& !@target(com.spt.development.logging.NoLogging)")
52+
@Around("@annotation(org.springframework.jms.annotation.JmsListener) && !loggingDisabled()")
5553
public Object log(final ProceedingJoinPoint point) throws Throwable {
5654
return super.log(point);
5755
}

src/main/java/com/spt/development/logging/spring/LoggerAspect.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.spt.development.cid.CorrelationId;
44
import org.aspectj.lang.ProceedingJoinPoint;
5+
import org.aspectj.lang.annotation.Pointcut;
56
import org.aspectj.lang.reflect.MethodSignature;
67
import org.slf4j.Logger;
78
import org.slf4j.LoggerFactory;
@@ -24,6 +25,9 @@ abstract class LoggerAspect {
2425
this.isStartAndCompleteMethodLoggedAtInfo = isStartAndCompleteMethodLoggedAtInfo;
2526
}
2627

28+
@Pointcut("@annotation(com.spt.development.logging.NoLogging) || @target(com.spt.development.logging.NoLogging)")
29+
void loggingDisabled() {}
30+
2731
Object log(final ProceedingJoinPoint point) throws Throwable {
2832
final MethodSignature signature = (MethodSignature) point.getSignature();
2933
final Logger log = LoggerFactory.getLogger(signature.getDeclaringType());

0 commit comments

Comments
 (0)