|
1 |
| -include::{commons}@data-commons::page$repositories/core-extensions.adoc[] |
| 1 | +[[core.extensions]] |
| 2 | += Spring Data Extensions |
| 3 | + |
| 4 | +This section documents a set of Spring Data extensions that enable Spring Data usage in a variety of contexts. |
| 5 | +Currently, most of the integration is targeted towards Spring MVC. |
| 6 | + |
| 7 | +include::{commons}@data-commons::page$repositories/core-extensions-querydsl.adoc[leveloffset=1] |
| 8 | + |
| 9 | +[[jpa.repositories.queries.type-safe.apt]] |
| 10 | +=== Setting up Annotation Processing |
| 11 | + |
| 12 | +To use Querydsl with Spring Data JPA, you need to set up annotation processing in your build system that generates the `Q` classes. |
| 13 | +While you could write the `Q` classes by hand, it is recommended to use the Querydsl annotation processor to generate them for you to keep your `Q` classes in sync with your domain model. |
| 14 | + |
| 15 | +Most Spring Data users do not use Querydsl, so it does not make sense to require additional mandatory dependencies for projects that would not benefit from Querydsl. |
| 16 | +Hence, you need to activate annotation processing in your build system. |
| 17 | + |
| 18 | +The following example shows how to set up annotation processing by mentioning dependencies and compiler config changes in Maven and Gradle: |
| 19 | + |
| 20 | +[tabs] |
| 21 | +====== |
| 22 | +Maven:: |
| 23 | ++ |
| 24 | +[source,xml,indent=0,subs="verbatim,quotes",role="primary"] |
| 25 | +---- |
| 26 | +<dependencies> |
| 27 | + <dependency> |
| 28 | + <groupId>com.querydsl</groupId> |
| 29 | + <artifactId>querydsl-jpa</artifactId> |
| 30 | + <version>${querydslVersion}</version> |
| 31 | + <classifier>jakarta</classifier> |
| 32 | + </dependency> |
| 33 | +</dependencies> |
| 34 | +
|
| 35 | +<build> |
| 36 | + <plugins> |
| 37 | + <plugin> |
| 38 | + <groupId>org.apache.maven.plugins</groupId> |
| 39 | + <artifactId>maven-compiler-plugin</artifactId> |
| 40 | + <configuration> |
| 41 | + <annotationProcessorPaths> |
| 42 | + <!-- Explicit opt-in required via annotationProcessors or |
| 43 | + annotationProcessorPaths on Java 22+, see https://bugs.openjdk.org/browse/JDK-8306819 --> |
| 44 | + <annotationProcessorPath> |
| 45 | + <groupId>com.querydsl</groupId> |
| 46 | + <artifactId>querydsl-apt</artifactId> |
| 47 | + <version>${querydslVersion}</version> |
| 48 | + <classifier>jakarta</classifier> |
| 49 | + </annotationProcessorPath> |
| 50 | + <annotationProcessorPath> |
| 51 | + <groupId>jakarta.persistence</groupId> |
| 52 | + <artifactId>jakarta.persistence-api</artifactId> |
| 53 | + </annotationProcessorPath> |
| 54 | + </annotationProcessorPaths> |
| 55 | +
|
| 56 | + <!-- Recommended: Some IDE's might require this configuration to include generated sources for IDE usage --> |
| 57 | + <generatedTestSourcesDirectory>target/generated-test-sources</generatedTestSourcesDirectory> |
| 58 | + <generatedSourcesDirectory>target/generated-sources</generatedSourcesDirectory> |
| 59 | + </configuration> |
| 60 | + </plugin> |
| 61 | + </plugins> |
| 62 | +</build> |
| 63 | +---- |
| 64 | +
|
| 65 | +Gradle:: |
| 66 | ++ |
| 67 | +==== |
| 68 | +[source,groovy,indent=0,subs="verbatim,quotes",role="secondary"] |
| 69 | +---- |
| 70 | +dependencies { |
| 71 | +
|
| 72 | + implementation 'com.querydsl:querydsl-jpa:${querydslVersion}:jakarta' |
| 73 | + annotationProcessor 'com.querydsl:querydsl-apt:${querydslVersion}:jakarta' |
| 74 | + annotationProcessor 'jakarta.persistence:jakarta.persistence-api' |
| 75 | +
|
| 76 | + testAnnotationProcessor 'com.querydsl:querydsl-apt:${querydslVersion}:jakarta' |
| 77 | + testAnnotationProcessor 'jakarta.persistence:jakarta.persistence-api' |
| 78 | +} |
| 79 | +---- |
| 80 | +==== |
| 81 | +====== |
| 82 | + |
| 83 | +Note that the setup above shows the simplemost usage omitting any other options or dependencies that your project might require. |
| 84 | + |
| 85 | +include::{commons}@data-commons::page$repositories/core-extensions-web.adoc[leveloffset=1] |
| 86 | + |
| 87 | +include::{commons}@data-commons::page$repositories/core-extensions-populators.adoc[leveloffset=1] |
0 commit comments