Skip to content

Commit 60487f3

Browse files
committed
Break cycle in spring-boot-data-* modules
There was a cycle in the spring-boot-data-* modules. SpringDataWebAutoConfiguration (which sits at the spring-data-commons level) referenced RepositoryRestMvcAutoConfiguration (which sits at the spring-data-rest level). This dependency's expressed in the wrong direction as data-rest depends on data-commons. The resulting cycle was not noticable as it was expressed through a String afterName attribute on `@AutoConfiguration`. spring-boot-data-commons was also using spring-boot-data-jpa for its tests, which also results in an inverted dependency relationship. This commit reworks things so that all of the spring-boot-data-* modules depend upon spring-boot-data-commons, mirroring the dependency relationship in Spring Data. The integration tests in spring-boot-data-commons have been reworked to use Spring Data directly, avoiding the need for a circular from spring-boot-data-commons to another spring-boot-data-* module.
1 parent dc7c736 commit 60487f3

File tree

21 files changed

+54
-173
lines changed

21 files changed

+54
-173
lines changed

spring-boot-project/spring-boot-data-cassandra/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ description = "Spring Boot Data Cassandra"
1111

1212
dependencies {
1313
api(project(":spring-boot-project:spring-boot-cassandra"))
14+
api(project(":spring-boot-project:spring-boot-data-commons"))
1415
api("org.springframework.data:spring-data-cassandra") {
1516
exclude group: "org.slf4j", module: "jcl-over-slf4j"
1617
}

spring-boot-project/spring-boot-data-commons/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ dependencies {
1515
optional(project(":spring-boot-project:spring-boot-autoconfigure"))
1616
optional(project(":spring-boot-project:spring-boot-metrics"))
1717

18-
testImplementation(project(":spring-boot-project:spring-boot-data-jpa"))
18+
testImplementation(project(":spring-boot-project:spring-boot-jdbc"))
1919
testImplementation(project(":spring-boot-project:spring-boot-test"))
2020
testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
2121
testImplementation(testFixtures(project(":spring-boot-project:spring-boot-autoconfigure")))
22+
testImplementation("org.springframework.data:spring-data-jdbc")
2223

2324
testRuntimeOnly("ch.qos.logback:logback-classic")
2425
testRuntimeOnly("com.h2database:h2")

spring-boot-project/spring-boot-data-commons/src/main/java/org/springframework/boot/data/metrics/MetricsRepositoryMethodInvocationListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class MetricsRepositoryMethodInvocationListener implements RepositoryMeth
5050
* @param tagsProvider provider for metrics tags
5151
* @param metricName name of the metric to record
5252
* @param autoTimer the auto-timers to apply or {@code null} to disable auto-timing
53-
* @since 2.5.4
53+
* @since 4.0.0
5454
*/
5555
public MetricsRepositoryMethodInvocationListener(Supplier<MeterRegistry> registrySupplier,
5656
RepositoryTagsProvider tagsProvider, String metricName, AutoTimer autoTimer) {

spring-boot-project/spring-boot-data-commons/src/main/java/org/springframework/boot/data/web/autoconfigure/SpringDataWebAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
* @author Yanming Zhou
4646
* @since 4.0.0
4747
*/
48-
@AutoConfiguration(afterName = "org.springframework.boot.data.rest.autoconfigure.RepositoryRestMvcAutoConfiguration")
48+
@AutoConfiguration
4949
@EnableSpringDataWebSupport
5050
@ConditionalOnWebApplication(type = Type.SERVLET)
5151
@ConditionalOnClass({ PageableHandlerMethodArgumentResolver.class, WebMvcConfigurer.class })
Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,19 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.data.metrics.autoconfigure.city;
17+
package org.springframework.boot.data.domain.city;
1818

19-
import java.io.Serializable;
19+
import org.springframework.data.annotation.Id;
2020

21-
import jakarta.persistence.Column;
22-
import jakarta.persistence.Entity;
23-
import jakarta.persistence.GeneratedValue;
24-
import jakarta.persistence.Id;
25-
26-
@Entity
27-
public class City implements Serializable {
28-
29-
private static final long serialVersionUID = 1L;
21+
public class City {
3022

3123
@Id
32-
@GeneratedValue
3324
private Long id;
3425

35-
@Column(nullable = false)
3626
private String name;
3727

38-
@Column(nullable = false)
39-
private String state;
40-
41-
@Column(nullable = false)
4228
private String country;
4329

44-
@Column(nullable = false)
45-
private String map;
46-
47-
protected City() {
48-
}
49-
5030
public City(String name, String country) {
5131
this.name = name;
5232
this.country = country;
@@ -56,21 +36,13 @@ public String getName() {
5636
return this.name;
5737
}
5838

59-
public String getState() {
60-
return this.state;
61-
}
62-
6339
public String getCountry() {
6440
return this.country;
6541
}
6642

67-
public String getMap() {
68-
return this.map;
69-
}
70-
7143
@Override
7244
public String toString() {
73-
return getName() + "," + getState() + "," + getCountry();
45+
return getName() + "," + getCountry();
7446
}
7547

7648
}
Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.data.metrics.autoconfigure.city;
17+
package org.springframework.boot.data.domain.city;
1818

19-
import org.springframework.data.domain.Page;
20-
import org.springframework.data.domain.Pageable;
21-
import org.springframework.data.jpa.repository.JpaRepository;
19+
import org.springframework.data.repository.CrudRepository;
2220

23-
public interface CityRepository extends JpaRepository<City, Long> {
24-
25-
@Override
26-
Page<City> findAll(Pageable pageable);
27-
28-
Page<City> findByNameLikeAndCountryLikeAllIgnoringCase(String name, String country, Pageable pageable);
29-
30-
City findByNameAndCountryAllIgnoringCase(String name, String country);
21+
public interface CityRepository extends CrudRepository<City, Long> {
3122

3223
}

spring-boot-project/spring-boot-data-commons/src/test/java/org/springframework/boot/data/metrics/autoconfigure/RepositoryMetricsAutoConfigurationIntegrationTests.java

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,20 @@
2222
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
2323
import org.junit.jupiter.api.Test;
2424

25-
import org.springframework.boot.autoconfigure.AutoConfigurationPackage;
2625
import org.springframework.boot.autoconfigure.AutoConfigurations;
2726
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
28-
import org.springframework.boot.data.jpa.autoconfigure.JpaRepositoriesAutoConfiguration;
29-
import org.springframework.boot.data.metrics.autoconfigure.city.CityRepository;
30-
import org.springframework.boot.jdbc.autoconfigure.EmbeddedDataSourceConfiguration;
31-
import org.springframework.boot.jpa.autoconfigure.hibernate.HibernateJpaAutoConfiguration;
27+
import org.springframework.boot.data.domain.city.City;
28+
import org.springframework.boot.data.domain.city.CityRepository;
29+
import org.springframework.boot.jdbc.autoconfigure.DataSourceAutoConfiguration;
30+
import org.springframework.boot.jdbc.autoconfigure.DataSourceInitializationAutoConfiguration;
31+
import org.springframework.boot.jdbc.autoconfigure.DataSourceTransactionManagerAutoConfiguration;
32+
import org.springframework.boot.jdbc.autoconfigure.JdbcTemplateAutoConfiguration;
3233
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
34+
import org.springframework.boot.testsupport.classpath.resources.WithResource;
3335
import org.springframework.context.annotation.Bean;
3436
import org.springframework.context.annotation.Configuration;
37+
import org.springframework.data.jdbc.repository.config.AbstractJdbcConfiguration;
38+
import org.springframework.data.jdbc.repository.config.EnableJdbcRepositories;
3539

3640
import static org.assertj.core.api.Assertions.assertThat;
3741

@@ -40,14 +44,22 @@
4044
*
4145
* @author Phillip Webb
4246
*/
47+
@WithResource(name = "schema.sql", content = """
48+
CREATE TABLE CITY (
49+
id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
50+
name VARCHAR(30),
51+
country VARCHAR(30)
52+
);
53+
""")
4354
class RepositoryMetricsAutoConfigurationIntegrationTests {
4455

4556
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
4657
.withBean(SimpleMeterRegistry.class)
47-
.withConfiguration(
48-
AutoConfigurations.of(HibernateJpaAutoConfiguration.class, JpaRepositoriesAutoConfiguration.class,
49-
PropertyPlaceholderAutoConfiguration.class, RepositoryMetricsAutoConfiguration.class))
50-
.withUserConfiguration(EmbeddedDataSourceConfiguration.class, TestConfig.class);
58+
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
59+
RepositoryMetricsAutoConfiguration.class, JdbcTemplateAutoConfiguration.class,
60+
DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class,
61+
DataSourceInitializationAutoConfiguration.class))
62+
.withUserConfiguration(TestConfig.class);
5163

5264
@Test
5365
void repositoryMethodCallRecordsMetrics() {
@@ -68,8 +80,8 @@ void doesNotPreventMeterBindersFromDependingUponSpringDataRepositories() {
6880
}
6981

7082
@Configuration(proxyBeanMethods = false)
71-
@AutoConfigurationPackage
72-
static class TestConfig {
83+
@EnableJdbcRepositories(basePackageClasses = City.class)
84+
static class TestConfig extends AbstractJdbcConfiguration {
7385

7486
}
7587

spring-boot-project/spring-boot-data-commons/src/test/java/org/springframework/boot/data/web/autoconfigure/domain/city/City.java

Lines changed: 0 additions & 76 deletions
This file was deleted.

spring-boot-project/spring-boot-data-commons/src/test/java/org/springframework/boot/data/web/autoconfigure/domain/city/CityRepository.java

Lines changed: 0 additions & 32 deletions
This file was deleted.

spring-boot-project/spring-boot-data-couchbase/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ description = "Spring Boot Data Couchbase"
1010

1111
dependencies {
1212
api(project(":spring-boot-project:spring-boot-couchbase"))
13+
api(project(":spring-boot-project:spring-boot-data-commons"))
1314
api("org.springframework.data:spring-data-couchbase")
1415

1516
optional(project(":spring-boot-project:spring-boot-autoconfigure"))

spring-boot-project/spring-boot-data-elasticsearch/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ plugins {
1010
description = "Spring Boot Data Elasticsearch"
1111

1212
dependencies {
13+
api(project(":spring-boot-project:spring-boot-data-commons"))
1314
api(project(":spring-boot-project:spring-boot-elasticsearch"))
1415
api("org.springframework.data:spring-data-elasticsearch")
1516

spring-boot-project/spring-boot-data-jdbc/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ plugins {
99
description = "Spring Boot Data JDBC"
1010

1111
dependencies {
12+
api(project(":spring-boot-project:spring-boot-data-commons"))
1213
api(project(":spring-boot-project:spring-boot-jdbc"))
1314
api("org.springframework.data:spring-data-jdbc")
1415

spring-boot-project/spring-boot-data-jpa/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ plugins {
99
description = "Spring Boot Data JPA"
1010

1111
dependencies {
12+
api(project(":spring-boot-project:spring-boot-data-commons"))
1213
api(project(":spring-boot-project:spring-boot-jpa"))
1314
api("org.springframework.data:spring-data-jpa")
1415
api("org.springframework:spring-aspects")
@@ -29,4 +30,5 @@ dependencies {
2930
testRuntimeOnly("ch.qos.logback:logback-classic")
3031
testRuntimeOnly("com.h2database:h2")
3132
testRuntimeOnly("com.zaxxer:HikariCP")
33+
testRuntimeOnly("jakarta.servlet:jakarta.servlet-api")
3234
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.data.web.autoconfigure;
17+
package org.springframework.boot.data.jpa.autoconfigure;
1818

1919
import org.junit.jupiter.api.Test;
2020

2121
import org.springframework.boot.autoconfigure.AutoConfigurations;
2222
import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage;
23-
import org.springframework.boot.data.jpa.autoconfigure.JpaRepositoriesAutoConfiguration;
24-
import org.springframework.boot.data.web.autoconfigure.domain.city.City;
25-
import org.springframework.boot.data.web.autoconfigure.domain.city.CityRepository;
23+
import org.springframework.boot.data.jpa.autoconfigure.domain.city.City;
24+
import org.springframework.boot.data.jpa.autoconfigure.domain.city.CityRepository;
25+
import org.springframework.boot.data.web.autoconfigure.SpringDataWebAutoConfiguration;
2626
import org.springframework.boot.jdbc.autoconfigure.DataSourceAutoConfiguration;
2727
import org.springframework.boot.jpa.autoconfigure.hibernate.HibernateJpaAutoConfiguration;
2828
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
@@ -42,7 +42,7 @@
4242
* @author Dave Syer
4343
* @author Stephane Nicoll
4444
*/
45-
class SpringDataWebAutoConfigurationJpaTests {
45+
class JpaRepositoriesSpringDataWebAutoConfigurationTests {
4646

4747
private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
4848
.withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class,

spring-boot-project/spring-boot-data-ldap/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ plugins {
99
description = "Spring Boot Data LDAP"
1010

1111
dependencies {
12+
api(project(":spring-boot-project:spring-boot-data-commons"))
1213
api(project(":spring-boot-project:spring-boot-ldap"))
1314
api("org.springframework.data:spring-data-ldap")
1415

spring-boot-project/spring-boot-data-mongodb/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ description = "Spring Boot Data MongoDB"
1010

1111
dependencies {
1212
api(project(":spring-boot-project:spring-boot"))
13+
api(project(":spring-boot-project:spring-boot-data-commons"))
1314
api(project(":spring-boot-project:spring-boot-mongodb"))
1415
api("org.springframework.data:spring-data-mongodb")
1516

spring-boot-project/spring-boot-data-neo4j/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ plugins {
1010
description = "Spring Boot Data Neo4j"
1111

1212
dependencies {
13+
api(project(":spring-boot-project:spring-boot-data-commons"))
1314
api(project(":spring-boot-project:spring-boot-neo4j"))
1415
api(project(":spring-boot-project:spring-boot-tx"))
1516
api("org.springframework.data:spring-data-neo4j")

0 commit comments

Comments
 (0)