SpringBoot3.0 Maven整合Querydsl

spring boot 3.0已经发布挺长时间了,个人最近尝试了一下,一直比较喜欢jpa,于是准备整合一波querydsl,但是网上旧帖和水帖较多,一直没找到简单直接且有效的攻略,于是在此献丑,贡献一份。

问题集合

  1. 主要问题,springboot升级3.0,jpa包路径从javax改成jakarta,在默认情况下,无法生存Q类,也没办法使用JPAQuery
  2. 官网和github在看起来似乎已经很长时间没有改动了,所以在这些地方不容易找出答案
  3. 网络攻略都是springboot2.0或者gradle方面

答案

  1. 引入依赖,重点:classifier标签
<dependency>
    <groupId>com.querydsl</groupId>
    <artifactId>querydsl-jpa</artifactId>
    <classifier>jakarta</classifier>
    <version>5.0.0</version>
</dependency>

<dependency>
    <groupId>com.querydsl</groupId>
    <artifactId>querydsl-apt</artifactId>
    <version>5.0.0</version>
    <scope>provided</scope>
    <optional>true</optional>
    <classifier>jakarta</classifier>
</dependency>
  1. 引入maven plugin,重点:dependency中的classifier
 <plugin>
    <groupId>com.mysema.maven</groupId>
    <artifactId>apt-maven-plugin</artifactId>
    <version>1.1.3</version>
    <executions>
        <execution>
		<!--<goals>-->
		<!--	<goal>process</goal>-->
		<!--</goals>-->
            <configuration>
                <outputDirectory>target/generated-sources</outputDirectory>
                <processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
            </configuration>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>com.querydsl</groupId>
            <artifactId>querydsl-apt</artifactId>
            <version>5.0.0</version>
            <classifier>jakarta</classifier>
        </dependency>
    </dependencies>
</plugin>
  1. 需要注意的一点,每个项目配置可能会有差别,在使用maven install时会报出一下错误,导致此错误的情况也不太一致。不过我这里,是因为配置了goals,导致install会出现这个错误,所以此处注释掉goals。其他情况不一定能适用此方式。
 Attempt to recreate a file for type xxx
  • 9
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
### 回答1: Maven 依赖是支持 SpringBoot 3.0 的。你可以在你的 pom.xml 文件中添加对 SpringBoot 3.0 的依赖。例如: ``` <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>3.0.9.RELEASE</version> </dependency> ``` 这样,Maven 就会下载并安装 SpringBoot 3.0 依赖包。 ### 回答2: Maven 是一个项目管理工具,用于构建和管理 Java 项目的依赖关系。SpringBoot 是一个基于 Spring 框架的快速开发框架,用于简化 Spring 应用程序的配置和开发。 根据目前(2021年)的信息,SpringBoot 的最新版本是 2.X 版本系列,而不是 3.0 版本。因此,目前的 Maven 依赖仍然支持 SpringBoot 2.X 版本。 在 Maven 的配置文件 pom.xml 中,我们可以通过设置相应的依赖项来使用 SpringBoot。可以使用 spring-boot-starter-parent 作为项目的父级依赖来简化 SpringBoot 项目的构建。 例如,在 pom.xml 文件中,我们可以添加以下依赖项: ``` <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.X.X</version> </dependency> <!-- 其他依赖项 --> </dependencies> ``` 这里的 version 标签可以指定所需的 SpringBoot 版本。当 SpringBoot3.0 版本发布时,我们可以更新 pom.xml 文件中的 version 标签以使用最新的版本。 总结而言,目前的 Maven 依赖支持 SpringBoot 2.X 版本,但不支持 SpringBoot 3.0 版本,因为目前还没有发布 3.0 版本。如果版本更新,我们可以在 pom.xml 文件中更新相应的版本标签来使用最新的 SpringBoot 版本。 ### 回答3: 目前(截至2021年11月),SpringBoot最新的稳定版本是2.5.x系列,不存在SpringBoot 3.0版本。因此,Maven依赖目前不支持SpringBoot 3.0SpringBoot 2.5.x系列的Maven依赖可以使用以下方式添加到项目中: 在pom.xml文件中,添加如下依赖配置: ```xml <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <version>2.5.5</version> </dependency> <!-- 其他SpringBoot相关依赖 --> </dependencies> ``` 请注意,实际使用时,可以根据具体需要选择更详细的依赖配置,比如添加Web相关功能支持、数据库支持等。 值得一提的是,对于未来可能发布的SpringBoot 3.0版本,具体是否会支持现有的Maven依赖配置,还需要根据官方发布的文档或公告来确认。通过关注SpringBoot的官方网站、邮件列表或GitHub仓库,可以获得最新的信息和更新。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值