Skip to content

Commit

Permalink
Add 'spring' module to replace 'spring5'
Browse files Browse the repository at this point in the history
  • Loading branch information
hgschmie authored and stevenschlansker committed Oct 25, 2024
1 parent d2f5b7f commit 78b7fe6
Show file tree
Hide file tree
Showing 42 changed files with 1,584 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/versions-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ jobs:

strategy:
matrix:
test-version: [ 5.3.39, 6.0.23, 6.1.9 ]
test-version: [ 6.0.23, 6.1.14 ]

steps:
- uses: actions/checkout@v4
Expand All @@ -474,7 +474,7 @@ jobs:
- name: run tests
id: run_tests
env:
MAVEN_ARGS: "-B -ff -pl :jdbi3-spring5 -Ddep.spring.version=${{ matrix.test-version }}"
MAVEN_ARGS: "-B -ff -pl :jdbi3-spring -Ddep.spring.version=${{ matrix.test-version }}"
run: |
./mvnw --version
make run-tests
Expand Down
4 changes: 3 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Unreleased

- spring aot: fix `@JdbiRepository` so aot generation works (#2727, thanks @hpoettker !)
- spring5: update spring dependency and tests to latest releases (dependabot #36 / CVE-2024-38820 asks for 5.3.41 but that is not released (neither is 5.3.40. Spring is a mess)).
- spring/spring5: update spring dependency and tests to latest releases (dependabot #36 / CVE-2024-38820 asks for 5.3.41 but that is not released (neither is 5.3.40. Spring is a mess)).
- deprecate the spring5 module as Spring Framework 5.x is no longer under OSS support
- add new `spring` module that will focus on Spring Framework 6.x and beyond. This is currently the same code as spring5 but no longer needs to maintain Spring Framework 5.x backwards compatibility.

# 3.46.0

Expand Down
5 changes: 5 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@
<version>${dep.jdbi3.version}</version>
<classifier>tests</classifier>
</dependency>
<dependency>
<groupId>org.jdbi</groupId>
<artifactId>jdbi3-spring</artifactId>
<version>${dep.jdbi3.version}</version>
</dependency>
<dependency>
<groupId>org.jdbi</groupId>
<artifactId>jdbi3-spring5</artifactId>
Expand Down
11 changes: 11 additions & 0 deletions docs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,17 @@
<groupId>org.jdbi</groupId>
<artifactId>jdbi3-postgres</artifactId>
</dependency>
<dependency>
<groupId>org.jdbi</groupId>
<artifactId>jdbi3-spring</artifactId>
<!--- it is always spring. always. -->
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-jcl</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jdbi</groupId>
<artifactId>jdbi3-spring5</artifactId>
Expand Down
46 changes: 27 additions & 19 deletions docs/src/adoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,10 @@ jdbi3-moshi::
[glossary]
jdbi3-guice::
Support dependency injection and modules with https://github.com/google/guice[Google Guice^].
jdbi3-spring::
Provides support for all https://spring.io/[Spring Framework^] versions that are under OSS support.
jdbi3-spring5::
Provides a https://spring.io/[Spring Framework^] factory bean to set up Jdbi singleton.
Provides a https://spring.io/[Spring Framework^] version 5 compatible factory bean to set up Jdbi singleton. _This module is deprecated, please migrate to the `spring` module._
jdbi3-jpa::
Some support for https://www.oracle.com/java/technologies/persistence-jsp.html[JPA^] annotations.

Expand Down Expand Up @@ -7830,22 +7832,19 @@ https://jdbc.postgresql.org/documentation/head/binary-data.html[Pg-JDBC docs^]
for upstream driver documentation.


=== Spring
=== Spring framework

This module integrates Jdbi and Spring / Spring Boot, including JTA support.
Jdbi supports https://spring.io[Spring Framework] with the `spring` module. It integrates Jdbi and Spring / Spring Boot, including JTA support.

The `spring5` module supports Spring 5 (Spring Boot 2) and newer.
We currently test with Spring 5 and Spring 6.

To use *jdbi-spring5*, add a dependency:
To use *jdbi-spring*, add a dependency:

For Apache Maven:

[source,xml,indent=0,subs="attributes,specialchars"]
----
<dependency>
<groupId>org.jdbi</groupId>
<artifactId>jdbi3-spring5</artifactId>
<artifactId>jdbi3-spring</artifactId>
<version>{project_version}</version>
</dependency>
----
Expand All @@ -7855,10 +7854,20 @@ For Gradle:
[source,groovy,subs="attributes,specialchars"]
----
dependencies {
implementation("org.jdbi:jdbi3-spring5:{project_version}")
implementation("org.jdbi:jdbi3-spring:{project_version}")
}
----

==== Supported versions

The `spring` module supports Spring 6.1 (Spring Boot 3.2.x) and newer. All versions of Spring framework that are under OSS support are supported. Other versions may work but are no tested and bug reports for older versions will not be addressed.

The deprecated `spring5` module supports Spring Framework version 5.x and 6.0. These versions are no longer under OSS support and updates
are no longer publicly available.

[NOTE]
The spring5 module will be removed in a future version of Jdbi! Please migrate to the `spring` module.


==== XML-based configuration
For XML-based configurations the class link:{jdbidocs}/spring5/JdbiFactoryBean.html[JdbiFactoryBean^] is made available to set up a
Expand Down Expand Up @@ -7891,7 +7900,7 @@ Then configure the Jdbi factory bean in your Spring container, e.g.:
<!--3-->
<bean id="jdbi"
class="org.jdbi.v3.spring5.JdbiFactoryBean">
class="org.jdbi.v3.spring.JdbiFactoryBean">
<property name="dataSource" ref="db"/>
</bean>
Expand All @@ -7903,10 +7912,9 @@ Then configure the Jdbi factory bean in your Spring container, e.g.:
</beans>
----

<1> The SQL data source that Jdbi will connect to. In this example we use an H2
database, but it can be any JDBC-compatible database.
<1> The SQL data source that Jdbi will connect to. In this example we use an H2 database, but it can be any JDBC-compatible database.
<2> Enable configuration of transactions via annotations.
<3> Configure link:{jdbidocs}/spring5/JdbiFactoryBean.html[JdbiFactoryBean^] using the data source configured earlier.
<3> Configure link:{jdbidocs}/spring/JdbiFactoryBean.html[JdbiFactoryBean^] using the data source configured earlier.
<4> Inject a link:{jdbidocs}/core/Jdbi.html[Jdbi^] instance into a service class. Alternatively, use standard JSR-330 `@Inject` annotations on the target class instead of configuring it in your `beans.xml`.


Expand All @@ -7917,7 +7925,7 @@ link:{jdkdocs}/java.base/java/util/ServiceLoader.html[ServiceLoader^] manifests.

[source,xml,indent=0]
----
<bean id="jdbi" class="org.jdbi.v3.spring5.JdbiFactoryBean">
<bean id="jdbi" class="org.jdbi.v3.spring.JdbiFactoryBean">
...
<property name="autoInstallPlugins" value="true"/>
</bean>
Expand All @@ -7927,7 +7935,7 @@ Plugins may also be installed explicitly:

[source,xml,indent=0]
----
<bean id="jdbi" class="org.jdbi.v3.spring5.JdbiFactoryBean">
<bean id="jdbi" class="org.jdbi.v3.spring.JdbiFactoryBean">
...
<property name="plugins">
<list>
Expand All @@ -7943,7 +7951,7 @@ auto-install some plugins and manually install the rest:

[source,xml,indent=0]
----
<bean id="jdbi" class="org.jdbi.v3.spring5.JdbiFactoryBean">
<bean id="jdbi" class="org.jdbi.v3.spring.JdbiFactoryBean">
...
<property name="autoInstallPlugins" value="true"/>
<property name="plugins">
Expand All @@ -7961,7 +7969,7 @@ Global defined attributes may be configured on the factory bean:

[source,xml,indent=0]
----
<bean id="jdbi" class="org.jdbi.v3.spring5.JdbiFactoryBean">
<bean id="jdbi" class="org.jdbi.v3.spring.JdbiFactoryBean">
<property name="dataSource" ref="db"/>
<property name="globalDefines">
<map>
Expand All @@ -7988,9 +7996,9 @@ public class JdbiConfiguration {
}
}
----
<1> This connection factory will enable <<spring5-jta, JTA support>>.
<1> This connection factory will enable <<spring-jta, JTA support>>.

[#spring5-jta]
[#spring-jta]
==== Synchronization between Jdbi and JTA
If you use Spring and databases, you will most likely also use the Java Transaction API (JTA)
to manage the transactions. The `JdbiUtil` utility can be used to obtain link:{jdbidocs}/core/Handle.html[Handles^]
Expand Down
2 changes: 1 addition & 1 deletion internal/build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
<dep.plugin.sortpom.version>3.3.0</dep.plugin.sortpom.version>
<dep.postgresql.version>42.7.2</dep.postgresql.version>
<dep.slf4j.version>1.7.36</dep.slf4j.version>
<dep.spring.version>5.3.39</dep.spring.version>
<dep.spring.version>6.1.14</dep.spring.version>
<dep.sqlite.version>3.44.1.0</dep.sqlite.version>
<dep.stringtemplate4.version>4.3.4</dep.stringtemplate4.version>
<dep.testcontainers.version>1.20.2</dep.testcontainers.version>
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<module>oracle12</module>
<module>postgis</module>
<module>postgres</module>
<module>spring</module>
<module>spring5</module>
<module>sqlite</module>
<module>sqlobject</module>
Expand Down
80 changes: 80 additions & 0 deletions spring/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.jdbi.internal</groupId>
<artifactId>jdbi3-parent</artifactId>
<version>3.46.1-SNAPSHOT</version>
</parent>

<groupId>org.jdbi</groupId>
<artifactId>jdbi3-spring</artifactId>

<name>jdbi3 spring</name>
<description>Support for Spring Framework and Spring Boot.</description>

<properties>
<moduleName>org.jdbi.v3.spring</moduleName>
</properties>

<dependencies>
<dependency>
<groupId>org.jdbi</groupId>
<artifactId>jdbi3-core</artifactId>
</dependency>
<dependency>
<groupId>org.jdbi</groupId>
<artifactId>jdbi3-sqlobject</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>
<dependency>
<groupId>org.jdbi</groupId>
<artifactId>jdbi3-testing</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jdbi.v3.spring;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.springframework.context.annotation.Import;

/**
* Annotating a spring configuration class with this annotation enables the scanning/detection of jdbi repositories.
* The scanned packages can be configured in the annotation. If no explicit configuration is done the package of the
* annotated element will be used as the sole base package.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Documented
@Import(JdbiRepositoryRegistrar.class)
public @interface EnableJdbiRepositories {

/**
* The names of the base packages used for repository scanning in addition
* to the {@link #basePackages} and {@link #basePackageClasses} properties.
*/
String[] value() default {};

/**
* The names of the base packages used for repository scanning in addition
* to the {@link #value} and {@link #basePackageClasses} properties.
*/
String[] basePackages() default {};

/**
* The packages of these classes are used as base packages for repository
* scanning in addition to the {@link #value} and {@link #basePackages}
* properties.
*/
Class<?>[] basePackageClasses() default {};

/**
* Exact array of classes to consider as repositories. Overriding any of
* the values defined in {@link #value}, {@link #basePackages} or
* {@link #basePackageClasses}.
*/
Class<?>[] repositories() default {};

}
Loading

0 comments on commit 78b7fe6

Please sign in to comment.